每次我点击一个按钮改变视图时,ios模拟器 5.1 (272.21)就会关闭。为什么?
- (IBAction)SwitchView:(id)sender {
SecondView *second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:NULL];
}
这是ViewController.m中的按钮代码。
没有报什么异常?再者,适当的改一下你的代码。如果不使用nib来初始化控制器,直接alloc init而不是你上面的写法。
- (IBAction)SwitchView:(id)sender {
SecondView *second = [[SecondView alloc] init];
[self presentViewController:second animated:YES completion:nil];
}
看你的SecondView,我想要问的是,你这上SecondView是直接或间接继承自UIViewcontroller吗,因为只有viewcontroller才能被present. 如果你的SecondView不是UIViewcontroller,你执行上面的代码,不会显示的话,原因应该就出在这里了。