简体   繁体   中英

iOS change view controller from the app delegate?

在此输入图像描述

Above is the storyboard for my chat app. What you'r not seeing to the left before the Navigation Controller is a simple login view. The Storyboard Segue identifier to the Navigation Controller is mainViewC .

What i want to do is to take the user to the Conv View Controller when a push notification is pressed.

This is what i've got so far:

// AppDelegate.h
@property (strong, nonatomic) ConvViewController *convViewController;

// AppDelegate.m
self.window.rootViewController = self.convViewController;

This takes me to the correct view but the view is black. Im guessing this has something to do with the Navigiation Controller not being loaded correctly..

Any ideas?

What you'll need to do is access the view controller from the story board. First go to the VC you wish to bring users to and give it a Storyboard ID. Then in your app delegate you would write.

self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"identifier"];

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