How can I switch views programmatically in a view controller? (Xcode, iPhone)

mishajw126 picture mishajw126 · Jun 7, 2012 · Viewed 114.8k times · Source

Have been struggling with this for a while, and can never seem to get a direct answer.

Any help is appreciated!

Answer

SlateEntropy picture SlateEntropy · Jun 7, 2012

If you're in a Navigation Controller:

ViewController *viewController = [[ViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];

or if you just want to present a new view:

ViewController *viewController = [[ViewController alloc] init];    
[self presentViewController:viewController animated:YES completion:nil];