当我第一次进入登录屏幕时,我将值存储在 NSUserDefaults
.当我按下 signinButtonAction
移至 DetailScreen
它卡住了,永远不会前进。
我做了DetailScreen
嵌入 Navigationcontroller
如InitialViewController
当我再次重新运行它时,即使下一个屏幕也没有导航到其他屏幕,它涉及 DetailScreen
然后 DetailScreen
卡住导航到其他屏幕。
我该如何处理?
我的代码在这里:AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"email"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
categoryVC *viewController = (categoryVC *)[storyboard instantiateViewControllerWithIdentifier:@"categoryVC"];
[self.window setRootViewController:viewController];
}
else
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
signInVC *viewController = (signInVC *)[storyboard instantiateViewControllerWithIdentifier:@"signInVC"];
[self.window setRootViewController:viewController];
}
在
SigninButtonAction
我在做:{
categoryVC * second= [self.storyboard instantiateViewControllerWithIdentifier:@"categoryVC"];
[self.navigationController pushViewController:second animated:YES];
}
最佳答案
我不会设置 RootViewController
如果你有这样的工作流程。我会按原样实例化主视图 Controller ,如果您需要显示身份验证,我会使用 presentViewController
.稍后,您可以执行解雇或类似的操作。
因此,在您的应用程序委托(delegate)中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (nil == [[NSUserDefaults standardUserDefaults] objectForKey:@"email"])
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
categoryVC *viewController = (categoryVC *)[storyboard instantiateViewControllerWithIdentifier:@"signInVC"];
[self.window.rootViewController presentViewController:viewController animated:NO];
}
}
然后,当您进行身份验证并通过时:
[self dismissViewControllerAnimated:TRUE completion:nil];
关于IOS:如何在第一次登录 ios 时处理 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28042278/