implementing a search Bar - ios

I am working on "implementing a search Bar"
When I work on "group table with multiple sections", Main.storyboard have View Controller and Table View it is run and display well like address list.
However, when I try to add the search Bar, I don't know how to deal with Main.storyboard. If I only have Table View Controller
I run it and display nothing.
If I have View Controller && Table View ,and also have Table View Controller, It have an error.
The code from the book is right, but to create Main.storyboard, the book explain very implicit.
By the way, what different between Table View Controller and use View Controller && Table View

The TableViewController comes with a tableView whose delegate and datasource are already set to be that TableViewController. This is normally used when it's ok for the table to take up the entire screen. The tableView is a normal view that you can add to any relevant ViewController. If this is the case, you must set its delegate and datasource and ensure that the corresponding ViewController conforms to UITableViewDelegate and UITableViewDataSource. The search bar would be a textField that would need a its delegate set. You can then write a search function to find whatever your text the user has in the textfield.

Related

Using the same table view cell in multiple view controllers

I have a custom table view cell class, which I use in several view controller's table views. I am adding a feature that gives the user the ability to delete a table view cell and I'd like to remove the cell from the table view when they do so.
Using a delegate is one way to achieve this, so that when the user deletes the table view cell, the table view cell class informs the view controller, through the delegate, that it was deleted and to remove it from the table view. However, this would mean I'd have to do this for each of my several view controllers, which I don't want to do.
So my question is, how can I implement this in such a way that I only have to write the code to remove the table view cell from the table view once?
Subclass the UITableView. Create a protocol like:
protocol customTableViewDelegate {
func deleteTableViewCell()
}
Then give the subclassed UITableView a variable of this type:
var removeCellDelegate: customTableViewDelegate?
And then instead of adding a normal UITableView to your view controller, add the custom one and set the removeCellDelegate to the view controller. Then implement the function to do whatever you want.

Can not drag and drop UITableViewController into Storyboard

A book I am using is telling me to drag and drop UITableViewController in object library into Main.storyboard, but it's not working. The UITableViewController just rushes back to object library. What's the problem? It works fine with "Table View". I am using Xcode 7.2, and OS X El Capitan.
Please help.
If you can't drag a Table View Controller to IB, then don't do it. Use a Table View instead! They are (mostly) the same.
I guess your book is telling you how to create a simple table view. So let me tell you how to create a simple table view in a view controller.
Of course, you should first drag a view controller to IB. Then add a table view to the view controller. Add the constraints if you want. Then run the app!
You will probably see a few horizontal lines on the screen and you can scroll it. How nice!
Now how do you add contents to the table? Just create a view controller class file and associate it with the view controller you just created. Then make that class conforms to the UITableViewDataSource protocol and add the required methods. Finally, just associate the class with the table view's data source property. I think your book will talk about this in detail.
If you want to know more, visit https://www.youtube.com/watch?v=s78ndDj8K3U&list=PL6gx4Cwl9DGDgp7nGSUnnXihbTLFZJ79B&index=21
You can't drop a view controller on top of another view controller.
(This is why you are able to drop a Table View onto a view controller, but not drop a Table View Controller.)
Instead, drag the Table View Controller to a blank area of the storyboard. It will be droppable, and appear on the storyboard.
Note that Interface Builder changes the appearance of the droppable object to include a + sign when it's over an area where it can be dropped (and added to the storyboard).

UITableViewController similar to Add Event Table View Controller of iOS7 calendar app

What is the proper approach to creating a table view controller that is used for user input and has all static cells in which some are text fields, some are date pickers, switches, etc.
My use case is exactly the same as the calendar application's. Table View Controller pushed modally when the user hits the plus button and the user enters data into a few text fields, flips some switches, and picks some dates.
Are the cells for this type of table view created programmatically using the provided datasource methods?
Storyboards are the only way to create static table views. You define an entire scene, and can define all cells as you like. You don't even need custom cell subclasses, you can connect labels and text fields defined in the cells as properties of the view controller directly, for easy access.
I have implemented a very similar view controller in our app using a Storyboard, where the entire scene is defined within the storyboard, including alert time and invitees. I implemented the initial view controller as a navigation controller, just like the EKEventEditViewController.

Populating a Text Field with a Selected Cell from a Separate Table View Controller

I have a working app which just needs some modification. It's a basic app with a Table View Controller that gets populated when a user taps the Plus button and fills in some information into text fields. The user will enter a name and event and I've made life easier by creating table view cells under the text fields so that when a user starts typing, it auto populates with the same names the user has entered before.
I'm using Core Data and NSFetchedResultsController. I'm modifying the app to be more seamless now for the user. Instead of the keyboard popping up when selecting the text field, I'm taking the user modally to another Table View Controller where the user can search, create or just select an existing entry from the Table View Cells.
I've got the new table view controller appearing and displaying the existing entries using NSFetchedResultsController and that's working well.
My question is: how do I go about selecting a Cell in the new Table View Controller and having that selection of the cell do two things:
1) Dismiss the Modal View
2) Populate the name text field (in the view controller that brought up the new Table View) with the selected name from the table view controller (that came up modally).
I have this working if the table view is in the same view controller, but I'm not quite sure how I would go about extracting that information from the other table view controller.
I'm guessing I would use protocols but I'm quite a newbie and so any pointing in the right direction or even some simple sample code would be massively appreciated!
Thanks,
You have to implement delegate protocol.
The idea is VC1 should conform the delegate (i.e. need to have a procedure -(void)dataAvail:(NSString *)data withViewController:(ViewController *)sender{...}). VC1 will push VC2 and set VC2.delegate = self.
In VC2, when cell is selected, just call [self.delegate dataAvail:self.yourTextField.text withViewController:self];
Now, in your VC1, you should implement dataAvail... just get the value and dismiss your modal VC2.
For more info on how to declare the protocol, just google for "ios delegate tutorial". delegate Protocol is used everywhere when coding for iOS (like MVC or KVC).

referencing UITableView to another tableview on a split view based app

I'd like to understand what's going on here. Basically I have a NumberOneViewController which owns a table view and is showing up on the details view controller on a split view based app.
When a user selects an entry on the NumberOneViewController tableview row, i assign the table view to RootViewController's tableView member like so:
self.tableView = numberOneViewController.tableView;
So the table view on the detail view controller is now gone - which brings me to my first question, what exactly happened here?
Now, I want number one view controller's table view again to show up on the details view controller, but how?
Maybe you need to reload/refresh the table view after you assign it. Just throwing out something off the top off my head since there are no other answers. Good Luck.

Resources