Hex*_*ark 1 xcode viewcontroller alertview
我想要实现的是在单击我的警报视图按钮时转到另一个视图.我的警报视图在我的loadingView中,这个警报视图是从另一个名为classA的类中调用的.
[LoadingViewController showError];
Run Code Online (Sandbox Code Playgroud)
+ (void)showDestinationError{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Error"
message:@"Error"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
alert.tag = DEST_ERR;
[alert show];
}
Run Code Online (Sandbox Code Playgroud)
+ (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];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是这一行:
[secondView presentModalViewController:secondView animated:YES];
Run Code Online (Sandbox Code Playgroud)
视图控制器不能呈现自身,并且在这种情况下甚至还不存在).
解决此问题的最明显方法是创建clickedButtonAtIndex
一个实例方法,因为它需要访问有关特定实例的信息.然后你会用这个:
[self presentModalViewController:secondView animated:YES];
Run Code Online (Sandbox Code Playgroud)
否则,您需要获得可以呈现视图控制器的视图的引用.有多种方法可以执行此操作,具体取决于您的应用程序的设置方式,包括从您的应用程序委托中获取或引用应用程序窗口.
归档时间: |
|
查看次数: |
3996 次 |
最近记录: |