【发布时间】:2014-04-02 11:37:16
【问题描述】:
我想在按下按钮时改变视图。 在根视图.h 我有这个:
@interface MainViewController : UIViewController
-(IBAction)switchToMap;
@end
在 .m 中我有这个:
-(IBAction)switchToMap
{
CustomViewController *customViewController = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];
customViewController.title = @"Mappa";
[self.navigationController pushViewController:customViewController animated:YES];
//[self.view addSubview:customViewController.view];
}
代码不起作用,但是如果我使用第二种方法[self.view addSubview:customViewController.view];works,我不知道为什么。
【问题讨论】:
-
确保在使用 inititWithRootViewController 的 navigationController 中有 MainViewController
-
因为没有可用的导航控制器,而不是将视图呈现为模态视图,它会工作