简体   繁体   中英

App crashes on iPhone 5 when calling the Viewcontroller in delegate

I have a project that works well in other simulators including The New iPad. However, with the iPhone5, it crashes when calling the Viewcontroller in delegate I don't know why this error happens. Please let me know if you discover any possible causes in the code below:

self.rootviewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 
self.rootNavController = [[UINavigationController alloc]
self.rootNavController.navigationBar.hidden=YES;
[window addSubview:rootNavController.view];'

Please see image below: 错误

Thank you very much

I think you do something wrong with the creation of your UINavigationController , try the following code to replace yours in your AppDelegate.m :

EDIT add code to display and remove splashscreen with UIViewController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Create View Controller
    RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

    // Create Navigation Controller
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

    // Create Navigation Controller
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];

    // SplashScreen
    [self displaySplashscreen];

    return YES;
}

#pragma mark - SplashScreen Methods
- (void)displaySplashscreen
{
    // Create View
    self.splashscreenViewController = [[SplashscreenViewController alloc] init];

    // Display Splashscreen
    [_window addSubview:_splashscreenViewController.view];

    // Dismiss Splashscreen
    [self performSelector:@selector(dismissSplashscreen) withObject:nil afterDelay:3.0f]; // Modify the time
}

- (void)dismissSplashscreen
{
    // Splashscreen Animation
    [UIView animateWithDuration:0.5f
                     animations:^{
                         _splashscreenViewController.view.alpha = 0.0f;
                     } completion:^(BOOL finished) {
                         [_splashscreenViewController.view removeFromSuperview];
                     }];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM