Pregunta

I got a very strange error when I try to present a viewcontroller from a UIAlertview button. It crashed on the prsentViewController line. Backtrace shows it failed to loadView. How can I fix this? The source code is below:

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

}
¿Fue útil?

Solución

With @rckoenes 's help I finally found the error after I hit a couple of times when I get the exception. It stops at UIViewController loadFromNibName because the line

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

returns a nib name but in the xib file with that name the root view is not a file outlet. After I link the view to file outlet the exception goes away.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top