1

我想要实现的是在单击警报视图按钮时转到另一个视图。我的警报视图在我的 loadingView 中,这个警报视图是从另一个名为 classA 的类中调用的。

这就是它在 A 类中的调用方式。

[LoadingViewController showError];

这是 loadingView 类的 loadingView 中的方法。

+ (void)showDestinationError{
UIAlertView *alert = [[UIAlertView alloc] 
                      initWithTitle:@"Error" 
                      message:@"Error"
                      delegate:self 
                      cancelButtonTitle:@"OK" 
                      otherButtonTitles: nil];
alert.tag = DEST_ERR;
[alert show];
}

按钮动作

+ (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag = DEST_ERR){

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    UINavigationController *secondView = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
    secondView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;    
    [secondView presentModalViewController:secondView animated:YES];
}
}

这给了我一个错误。'应用程序试图在其自身上呈现模态视图控制器。呈现控制器是 UINavigationController:..

注意:我的方法是'+'

4

1 回答 1

5

问题是这一行:

[secondView presentModalViewController:secondView animated:YES];

视图控制器不能呈现自己,在这种情况下甚至还不存在)。

解决此问题的最明显方法是创建clickedButtonAtIndex一个实例方法,因为它需要访问有关特定实例的信息。然后你会使用这个:

[self presentModalViewController:secondView animated:YES];

否则,您需要获取对可以呈现您的视图控制器的视图的引用。有多种方法可以做到这一点,具体取决于您的应用程序的设置方式,可能包括从您的应用程序委托获取它或引用应用程序窗口。

于 2012-04-25T04:05:29.787 回答