A: 

It sounds like you're not retaining tripDetails object, so it's getting released before you try to use.

Mike
I was already retaining the tripDetails object in initWithNibName method (see code above) and now also added a retain in the code where the tripDetails object is created. This had no effect.I wonder if the problem is retainment of the tripDetails object itself, because the pointer value of the TripDetailsController instance is different in the viewDidLoad and the initWithNibName methods. I'm expecting that the problem lies in that area. Why are there two instances of the TripDetailsController? I only create one.
Gero
You don't need the retain since the property (presumably) retains it. If it WERE getting released for some reason, you'd have an exception when you try to access a deallocated object instead of the ivar becoming nil.
Daniel Dickison
A: 

You should post the code that calls initWithNibName:bundle:.

My hunch is that you're creating one programatically, but the one that's actually getting used is being created in a NIB file. Maybe your main view NIB creates a TripDetailsController as a tab view or navigation root. In that case, initWithCoder: gets called instead of initWithNibName:bundle:, which would explain the uninitialized td ivar.

Daniel Dickison
The code that calls the initWithNameName:bundle:tripDetails is included above. It is the first code snippet. The rest of the code is the implementation of the TripDetailsController.
Gero
Second note: nitWithNameName:bundle:tripDetails does get invoked since did set a breakpoint there and execution stopped there.
Gero
That is indeed very strange. Looking at your code, I don't see how tdController in getTripDetails can be a different instance than the one that receives viewDidLoad. The only thing I can think of is that the debugger is actually executing an older version of the code... I've had this happen when I changed the product ID of the build target.
Daniel Dickison
With UIViewControllers, you sometimes get strange behavior if you don't use viewDidLoad for setup (or perform externally after the initialization). I edited my answer after remembering this. I guess this is why Apple tells you to use viewDidLoad for additional setup.
Corey Floyd
I added an explicit call to viewDidLoad() before doing the pushViewController and in that case that invocation of viewDidLoad is OK. However, the pushViewController also triggers a viewDidLoad and then the instance of TripDetailsController is different again (and the tripDetails property is nil)
Gero
A: 

Wait, I have seen this before:

Instead of making a custom initializer, use the standard one and try this:

TripDetails td = ...;   // td has a value
TripDetailsController *tdController = [[TripDetailsController alloc] initWithNibName:@"TripDetailsController" bundle:[NSBundle mainBundle]];
[tdController setTripDetails:td]

[self.navigationController pushViewController:tdController animated:YES];
[tdController release];


Original answer: In the TripDetailsController interface, is the thipDetails property set to retain? (and not assign).

Corey Floyd
This was my original approach and has the same effect as the approach I listed in the original post. The pointer value of 'tdController' is different than the value of 'self' in the TripDetailsController.viewDidLoad method (and the tripDetails attribute is nil in viewDidLoad).Yes, the tripDetails property is set to retain in the .h file.
Gero
Shouldn't matter with this class, but are you doing if(self=[super initWithNib:bundle:])? Weird that self isn't the same object. I would try rewriting this code in another project and see what happens. It sounds like you have some hard to track down bug.
Corey Floyd
A: 

I found a way to get it working by following the sample code from the SimpleDrillDown example from Apple.

Main differences with my original code:

  • TripDetailsController is no longer defined in .xib file
  • TripDetailsController no longer loaded from .xib file, but initialized as follows:

Code:

TripDetailsController *tdController = 
    [[TripDetailsController alloc] initWithStyle:UITableViewStyleGrouped];
  • TripDetailsController is no longer a UIViewController, but a subclass of UITableViewController

As a result I had to tweak the layout a bit, but at least it now works.

Looks as if it is not possible to initialize a view controller from a XIB file and then push it on to the navigation controller.

Gero

Gero