我正在尝试编写一个IBAction来切换我的iPhone应用程序的视图控制器:
-(IBAction)changeToView2:(id)sender
{
if (self.view2 == nil)
{
view2 = [[UIViewController alloc] initWithNibName:@"View2Controller" bundle:[NSBundle mainBundle]];
}
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentedViewController: view2 animated:YES];
}
但是,我收到一个构建错误,注意没有接口声明“presentViewController:animated:”。为什么呢?
将其更改为“presentViewController:animated:”会产生相同的错误。
答案 0 :(得分:7)
该方法为presentViewController:animated:completion:
,而不是present
ed ViewController:animated:
答案 1 :(得分:1)
而不是
[self presentedViewController: view2 animated:YES];
试
[self presentViewController: view2 animated:YES];
答案 2 :(得分:1)
[self presentViewController:view2 animated:YES];
答案 3 :(得分:0)
尝试使用您编辑的代码。我认为这对您有所帮助。
-(IBAction)changeToView2:(id)sender
{
if (self.view2 == nil)
{
view2 = [[UIViewController alloc] initWithNibName:@"View2Controller" bundle:nil];
}
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentedViewController: view2 animated:YES];
}