0

当我尝试从 UIAlertview 按钮显示视图控制器时,我遇到了一个非常奇怪的错误。它在 prsentViewController 行上崩溃了。Backtrace 显示它无法加载视图。我怎样才能解决这个问题?源代码如下:

- (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;
        }
    }

}
4

1 回答 1

0

在@rckoenes 的帮助下,我在遇到异常几次后终于找到了错误。它停在 UIViewController loadFromNibName 因为该行

[NSStringFromClass([UINewUserAccountViewController class]) stringByAppendingString:@"~iPhone"]

返回一个 nib 名称,但在具有该名称的 xib 文件中,根视图不是文件出口。在我将视图链接到文件出口后,异常消失了。

于 2014-05-09T01:34:28.603 回答