在viewdidload方法中切换视图控制器

发布于 2024-11-19 16:03:49 字数 540 浏览 2 评论 0原文

我正在开发一个 iPhone 应用程序,因为我想通过检查用户默认值来切换视图控制器。所以我做了以下操作:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults objectForKey:@"keyString"] != nil) {
    nextViewController *redirectView = [[nextViewController alloc] initWithNibName:@"nextViewController" bundle:[NSBundle mainBundle]];
self.nextView = redirectView;
[self presentModalViewController:self.nextView animated:YES];
} else {
[defaults setObject:@"newValue" forKey:@"keyString"];
}

它不起作用..这是正确的方法吗???如果没有的话谁能告诉我该怎么做..

I am developing one iphone application in that i want to switch view controller by checking userdefaults. so i did the following:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults objectForKey:@"keyString"] != nil) {
    nextViewController *redirectView = [[nextViewController alloc] initWithNibName:@"nextViewController" bundle:[NSBundle mainBundle]];
self.nextView = redirectView;
[self presentModalViewController:self.nextView animated:YES];
} else {
[defaults setObject:@"newValue" forKey:@"keyString"];
}

Its not working.. Is this the right way??? If not can anyone tell me how to do that..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绻影浮沉 2024-11-26 16:03:49

不要将redirectView分配给self.nextView。直接这样传过去

[self presentModalViewController:redirectView animated:YES];

Dont assign redirectView to self.nextView. Pass it directly like this

[self presentModalViewController:redirectView animated:YES];
韵柒 2024-11-26 16:03:49

添加该行

[self.view addSubview:nextView]; 

而不是

[self presentModalViewController:self.nextView animated:YES];

Add the line

[self.view addSubview:nextView]; 

instead of

[self presentModalViewController:self.nextView animated:YES];
來不及說愛妳 2024-11-26 16:03:49
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults objectForKey:@"keyString"] != nil) 
{ nextViewController *redirectView = [[nextViewController alloc]init]; 
[self presentModalViewController:redirectView animated:YES]; 
redirectView=nil;
 } 
else { 
[defaults setObject:@"newValue" forKey:@"keyString"]; 

}

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if ([defaults objectForKey:@"keyString"] != nil) 
{ nextViewController *redirectView = [[nextViewController alloc]init]; 
[self presentModalViewController:redirectView animated:YES]; 
redirectView=nil;
 } 
else { 
[defaults setObject:@"newValue" forKey:@"keyString"]; 

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文