views:

168

answers:

2

I'm doing the fourth assignment on the Stanford Iphone Dev Course.

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch

    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
    ListViewController *listview = [[ListViewController alloc] initWithNibName:@"ListView" bundle:[NSBundle mainBundle]];
    [[self navigationController] pushViewController:listview animated:NO];
    [listview release];
}

So, i'm trying to get my get my listview inside of the navigationcontrollers view. but the thing that happens is that the listview gets a new view with a "back to rootcontroller" button in the navigation bar. and when i click it i get back to the navigationcontroller view that is empty.

what am i doing wrong?

+2  A: 

if you want your ListViewController to be rootViewController, you should do smth like this

[navigationController setViewControllers:[NSArray arrayWithObject:listView] animated:YES];

instead of pushViewController. pushViewController just add your listView to the top of the controller's stack. initial viewController stays with an empty view.

Morion
Thats what im trying to do, how do i add it to the stack?
Oscar
sorry, i read your answer wrong, ignore the above.
Oscar
A: 

You can also assign your ListViewController as the root view controller for your navigation controller during instantiation:

[[UINavigationController alloc] initWithRootController:listview ]
ennuikiller