Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

presentModalViewController not working

here's my code:

ViewController *vc = [[ViewController alloc] initWithNibName:@"TableView" bundle:nil];
[self.navigationController presentModalViewController:vc animated:YES];
//[self setView:[vc view]];

If I call it, nothing happens. However, if I change it to:

ViewController *vc = [[ViewController alloc] initWithNibName:@"TableView" bundle:nil];
//[self.navigationController presentModalViewController:vc animated:YES];
[self setView:[vc view]];

The view appears just fine (without the transition, of course). What am I doing wrong? Is there anything special you have to take care of when initializing the view controller? I tried to copy as much as possible from Apple's examples, but I can't get this to work...

Thanks for any input!

-- Ry

like image 990
ryyst Avatar asked Mar 21 '10 15:03

ryyst


1 Answers

You can only present modal view controllers from controllers that have already been shown onscreen (usually through a UINavigationController or UITabBarController). Try creating a UINavigationController, pushing a viewController to it, and then presenting your modal controller. There's a starter project in Xcode that shows how to create a UINavigationController-based flow if you're unfamiliar with it.

One other thing to note: if you haven't pushed the view controller onto a UINavigationController, the .navigationController property will be nil, and messaging it will have no effect.

like image 162
Ben Gottlieb Avatar answered Oct 11 '22 12:10

Ben Gottlieb