views:

48

answers:

1

I have a view controller:

@interface DetailViewController : UIViewController

It displays a map and pins are dropped onto this map. When the user tap's the accessory button one of the annotation views I want another view to be pushed in front of the user.

For some or other reason the navigation controller is always null when I run the following code.

hotelDetailViewController = [[HotelDetailViewController alloc] initWithNibName:@"HotelDetailViewController"
                                                                        bundle:nil];

if (![self navigationController])
{
    NSLog(@"navigation controller null");
}

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

What am I doing wrong? At what point to do I need to alloc and init the navigation controller because it seems to be read only?

+3  A: 

At what point to do I need to alloc and init the navigation controller because it seems to be read only?

Well, you don't usually set the navigationController property yourself, you would typically have a navigation controller set up from the start and then pass your DetailViewController to the navigation controller, and that's when the property is set.

The section in the View Controllers programming guide about Navigation Controllers explains how you should set up your navigation controller, either with a nib file or programmatically.

filipe