Objective-C: navigationController pushViewController & NIBs
I have some issues with pushViewController. Essentially so far I have a class (UIViewController) that is essentially a UITableView (i have delegates for UITable) and it shows the UITable fine. Now I want this to be a hierarchical table that goes down to another controller...
Problem is, prior to me making this change, the NIB file because of its structure has a file owner and its a second tab item (so there is no UIApplicationDelegate in the current controller bu开发者_开发百科t there is for the App). I have a window with a view and a UITable underneath that.
So my first controller is:
@interface PostsViewController : UIViewController{
//@private
NSFetchedResultsController *fetchedResultsController;
UITableView *tableView;
UINavigationBar *navBar;
}
I believe I am meant to change this to be a navcontroller or something, to be able to push a view controller with a navbar on top that links backwards?
How do I go about doing this?
Thanks
Your initial view controller will be a UINavigationController
instead of your current table view controller. You then push your table view controllers onto this navigation controller.
The navigation controller takes care of the navigation bar, so you can remove that from your PostsViewController.
Your PostsViewController will know when it has been added to a UINavigationController; its navigationController
property will be set. You use this property to access your current view controller for pushing and popping other view controllers.
Your application needs to have a UIApplicationDelegate
.
In its applicationDidFinishLaunching:
method add a navigation controller to the window and the push the first UITableViewController
as the root.
To see an example of the code create a new Navigation-based application in Xcode and look at its applicationDidFinishLaunching:
method.
精彩评论