在我的应用程序委托(delegate)中,如果保存了用户详细信息,我会将用户推送到 View Controller
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
// cached user
PFUser *currentUser = [PFUser currentUser];
if (currentUser)
{
NSLog(@"current user signing and looking for VC %@", currentUser);
// A user was cached, so skip straight to the main view
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
TaskSelectionViewController*viewController = [[TaskSelectionViewController alloc] initWithUser:currentUser];
[navigationController pushViewController:viewController animated:YES];
NSLog(@"VC found");
} else {
NSLog(@"VC not found");
}
TaskSelectionViewController.m
-(id)initWithUser:(PFUser *)currentUser
{
NSLog(@"current user %@", currentUser);
NSLog(@"task Selection initwithuser");
return self;
}
推送有效,但我得到的只是顶部的 NavigationController 栏和黑屏。
缺少什么??
感谢您的帮助。
最佳答案
好的,使用 instantiateViewControllerWithIdentifier:@"ID"完成
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
TaskSelectionViewController *controller = (TaskSelectionViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"task"];
[navigationController pushViewController:controller animated:YES];
关于ios - appdelegate 如何使用 Storyboard推送 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14153453/