I already have a view controller, is it possible to attach a table view on top of the current view, without the needed to create a subclass of UITableViewController?
Thanks
Yes, just set up the table view like any other view and connect it to your viewcontroller by setting the delegate (reference) and dataSource (reference) - properties. See the references on which method you have to implement in your viewcontroller in order to get things working.
Related
I have an application that has multiple viewcontrollers and one common menu table.
Menu table is same in all viewcontrollers. Currently, If i want to add some more menu in my menu table then I have to change in all the view controllers.
Can we have a common table view which can be called in different viewcontrollers?
Thanks
Make a subclass of UITableView and create your menu in that like :
#interface menuTable : UITableView
Then you can use the instance of that class in all viewControllers.
Yes, you can.
When you add UIView to some other UIView, former will be removed from it's Superview and added to latter as subview. Remember to be careful with view's frame. e.g. convert it using convertRect:toView: selector
As I understand ur question, just create a tableView in CommonView (a ref. name) and as per your need you can call that table view. By this way you have to not change many times in your code.
Is it possible to create and display a UITableView controller which allows the user to select an item and fire back a message to the delegate without subclassing it?
The reason is I just want to display a list of items in a popovercontroller and it seems a waste to have to create a subclass just for this
In the view controller that presents the popover you could implement UITableViewDataSource and UITableViewDelegate - then set the popover's tableview to use the parent controller as its source and delegate before presenting it.
If you are using iOS 5 SDK then you can make static cells.
Otherwise the only option is to create a subclass and provide a DataSource array.
Either ways you might want to have a View Controller that prepares the view controller loaded on the touch action?
UItableView style not changing. I have a tableView controller as one of the tabs of my tab bar controller. I am not able to change the style of UItableView to grouped.
Please help,
You must specify the Tableview's style upon creation. Either in IB or by using the method
tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,416) style:UITableViewStyleGrouped];
I would create a new tableViewController and make sure to enable the "also create xib"-like option when giving the tableviewcontroller a name. Copy paste all youre old tablviewcontroller code to the new one and add the xib to the tab window..
You can probably do that in your UITableViewControllers -viewDidLoad method.
self.tableView.style = UITableViewStyleGrouped;
Edit:
It seems the style property is actually read only, so the above won't work.
It looks like the table view controller has to be created with -initWithStyle:, but I don't know how to do that from Interface Builder. I'm not at my Mac right now, but will have a look later.
Edit 2:
Here's what I did in Interface Builder:
Add an instance of UITableView and set it up as required, including the style
Hook up your UITableViewController as the delegate and data source of the UITableView
Connect the UITableView with the view outlet of the UITableViewController. I'm not sure if there is a tableView outlet - if there is, then probably connect it with that one instead.
So, basically, instead of letting the UITableViewController create its own table view, you provide one in the xib and set up the required connections (delegate, data source, outlet) manually.
I have a bunch of connection related methods that I need to execute before the table is actually being populated (before any of the delegate methods for a UITableView are called). The connection methods will add objects in a NSMutableArray that will later be used to populate the table view.
Is there a way to tell the iPhone to wait until all the connection methods are done, before it starts with the delegate methods relating to a UITableView in a UITableViewController?
Cheers!
Cant you just do a [table reloadData] when you are finished with all the connections? All the delegate methods really should be safe to use if the data source is still empty.
I had a similar issue. What you can try is to not set the table view's datasource and delegate properties until after your connection methods are done. In IB, don't hook up the datasource and delegate connectors of the table view (leave them unconnected). Then in code, when your connection methods are done, set the datasource and delegate to self and call reloadData on the table view.
A common pattern used when setting up a table view, is to create the view controller, set data within the view controller, and then present the view controller (modally or otherwise). The table view will not start requesting data until you try to display it, creating a view controller does not create the view until the view is requested.
I have a tab bar application. In one of my tabs, there is a search bar and a table view below that. When you enter something into the search bar, it returns parsed xml. I need to put this parsed information into the tableview below. The class inherits from UIViewController. I declared a UITableView object in the header file and linked it in interface builder, and adopted the UITableViewDelegate protocol.
I'm not sure If i'm going about this the correct way. Any help?
That sounds about right. You will need to also have your UIViewController implement UITableViewDataSource, and add the methods from that protocol to populate the table.
There are various tutorials available which guide you step-by-step to create a simple tablview. Google them. You can follow these steps for connecting your tableView outlets:
Select your viewController where you are displaying the tableview to be your "File's Owner" in Identity Inspector.
Drag your view's outlet to your File's owner.
For tableView inside view, drag its outlets to File's owner again so that your datasource and delegates are up. And in the same view, drag your referencing outlet to the IBOutlet you have created in your viewController class.