当我尝试从UIAlertview按钮呈现视图控制器时,我遇到了一个非常奇怪的错误。 它在prsentViewController行崩溃了。 Backtrace显示它无法加载View。我怎样才能解决这个问题?源代码如下:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView == _alertView) {
switch (buttonIndex) {
case 0:
{
[alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
}
break;
default:
{
NSString *nibName = IS_IPAD? NSStringFromClass([UINewUserAccountViewController class]) : [NSStringFromClass([UINewUserAccountViewController class]) stringByAppendingString:@"~iPhone"];
UINewUserAccountViewController *newUserAccountViewController = [[UINewUserAccountViewController alloc] initWithNibName:nibName bundle:nil];
newUserAccountViewController.delegate = self;
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:newUserAccountViewController];
[self presentViewController:navi animated:YES completion:nil];
}
break;
}
}
}
答案 0 :(得分:0)
在@rckoenes的帮助下,当我得到异常后,我终于找到了几次错误。它停在UIViewController loadFromNibName,因为行
[NSStringFromClass([UINewUserAccountViewController class]) stringByAppendingString:@"~iPhone"]
返回一个nib名称,但在具有该名称的xib文件中,根视图不是文件出口。将视图链接到文件出口后,异常就消失了。