1

I'm having some problems with a Navigation controller in my app. Moving from the RootViewController to a UITableViewController works fine. I now want to have one more level of drilldown, so users pick an item from the list and a new screen appears, like this:

RootViewController --> TableViewController --> ItemViewController

I've used the exact same code that switches the first views, but I get:

Application tried to push a nil view controller on target <UINavigationController...

The code is identical to the first one, so how can it be nil?

In RootViewController.h:

@interface RootViewController : UIViewController {
    IBOutlet TableViewController *tableViewController;
}

@property (nonatomic, retain) TableViewController * tableViewController;

In the .m file I synthesize the property and then use a button to call:

[self.navigationController pushViewController:tableViewController animated:YES];

In TableViewController.h:

#import "ItemDetailViewController.h"

@class TableViewController;

@interface TableViewController : UITableViewController {
    IBOutlet ItemDetailViewController * itemDetailViewController;
}

@property (nonatomic, retain) ItemDetailViewController * itemDetailViewController;

@end

And again, I synthesize it in the .m file and use code to push the new view in didSelectRowAtIndexPath:

[self.navigationController pushViewController:itemDetailViewController animated:YES];

When you tap on an item I get the error message above. Does anyone have any idea why this is happening?

3
  • What is the connection between 'itemDetailViewController' and 'plantDetailViewController'? Commented Jun 2, 2011 at 16:33
  • Sorry, typo! Changed the names to make it easier to read. Commented Jun 2, 2011 at 16:35
  • 3 nibs, one for each view. RootViewController, TableViewController, ItemViewController. Commented Jun 2, 2011 at 16:50

1 Answer 1

1

This most common cause of this error is failing to connect itemDetailViewController to the actual object in IB. Note that you should generally place the IBOutlet designator on the property rather than on the ivar.

Sign up to request clarification or add additional context in comments.

7 Comments

Everything is connected up as per the RootViewController, and all connections are there and correct. I will however switch the IBOutlet designators, maybe its that?
In the debugger, is itemDetailViewController nil? Is it nil in TableViewController viewDidLoad? If so, then you're not connected to what you think you're connected to.
How can I check that? Do you mean use instruments and check for memory allocation?
Okay just did an if statement to check if self.itemDetailViewController is nil, and it is. Any idea why? Everything is definitely connected up the same as the first view.
You can also set a breakpoint and po itemDetailViewController. A common reason is that your NIB has not loaded yet (viewDidLoad has not run). This doesn't happen until the view is first accessed. Another common mistake is having duplicate objects. This commonly happens when people wire an object in the NIB and also create an object of the same class using +alloc. The two objects are unrelated. Another possibility is that you're not loading the NIB you think you are. Put breakpoints in -viewDidLoad and see when things happen.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.