4

我正在尝试编写一个 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];
}

但是,我收到一个构建错误,指出没有接口声明“presentedViewController:animated:”。为什么?

将其更改为“presentViewController:animated:”会产生相同的错误。

4

4 回答 4

7

方法是presentViewController:animated:completion:,不是presentedViewController:animated:

于 2012-04-30T18:00:28.640 回答
1

代替

[self presentedViewController: view2 animated:YES];

尝试

[self presentViewController: view2 animated:YES];
于 2012-04-30T18:01:18.390 回答
1
[self presentViewController:view2 animated:YES];
于 2012-04-30T18:01:27.970 回答
0

试试这个你编辑的代码。我认为这对你有帮助。

-(IBAction)changeToView2:(id)sender 
{
if (self.view2 == nil)
{
    view2 = [[UIViewController alloc] initWithNibName:@"View2Controller" bundle:nil];
}
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentedViewController: view2 animated:YES];
}
于 2012-05-07T05:20:11.513 回答