views:

683

answers:

2

Hi guys,

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 but 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

+1  A: 

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.

Ben S
Hi mate no I meant my app has an AppDelegate but my current view controller/table controller doesn't. The issue is not this but I mentioned it for purpose of knowing what is available to hookup for view etc
Doron Katz
+1  A: 

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.

Darren
HI Darren I made the class changes to change the type to UINavigationController but when i build i get a blank screen. So what do i need to do in terms of re-configuration or configuration on the XIB/NIB side?
Doron Katz
Note, currently the tables in the UINavigationController) are populated via CellForRowAtINdexPath etc.
Doron Katz
You don't change your NIB. You change the code in your app delegate where the initial view controller is created and added to your window. Right now it's adding your PostsViewController to the window. Instead, create a generic UINavigationController and add that to your window. Then add your PostsViewController to the navigation controller.
Darren
hi Darren, I load a tabbar via NIB (not programatically) and the second tab links to the NIB that the UINavigationController class is associated with. I therefore dont use app delegate code to programatically add the UITabbar controller (first view) and UINavigationcontroller
Doron Katz
With Interface Builder you can drop a UINavigationController into your Tab View Controller, then drop your existing PostsViewController into this navigation controller.
Darren
Thanks Darren. Worked. Basically i did as you said in last comment, created in UI NavigatorController and added my own UIViewController in, and it automagically takes care of it. Ta!
Doron Katz