[英]iOS/xcode/objective-c: How to instantiate view controller after signup
After a successful sign up, I want users to go through a process where they provide photo etc. Similar code to that below worked to load the login page but code below is not working to load a separate view controller in storyboard "newuser". 成功注册后,我希望用户经历一个提供照片等的过程。类似于下面的代码可用于加载登录页面,但下面的代码不适用于在故事板“ newuser”中加载单独的视图控制器。
Would appreciate any suggestions on how to fix. 将不胜感激有关如何修复的任何建议。
- (void)presentNewUserInterface
{
UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"newuser"];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window.rootViewController = navigation;
}
Two variants: 两种变体:
Replace window.rootViewController with your next view controller. 用下一个视图控制器替换window.rootViewController 。 Do it on AppDelegate class.
在AppDelegate类上执行此操作。
Present new view controller from current root view controller. 从当前的根视图控制器呈现新的视图控制器。 Do it in your sign up view controller.
在您的注册视图控制器中执行此操作。
The lack of the first method is no transaction animation. 第一种方法的不足是没有交易动画。 So second method is preferable.
因此,第二种方法是可取的。
Instead of: 代替:
- (void)presentNewUserInterface
{
UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"newuser"];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
self.window.rootViewController = navigation;
}
Try: 尝试:
- (void)presentNewUserInterface
{
UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"newuser"];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:rootController];
[self presentViewController:navigation animated:YES completion:nil];
}
You aren't presenting your new navigation controller in your example. 您没有在示例中展示新的导航控制器。 Is there a particular reason why you would be trying to replace your rootViewController?
有特定的原因为什么您要尝试替换rootViewController? That shouldn't be needed.
那不是必需的。 My example should be sufficient for displaying your next flow in the user sign up process.
我的示例足以显示用户注册过程中的下一个流程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.