Switching view controller in viewdidload method
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" 开发者_StackOverflowbundle:[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..
Dont assign redirectView to self.nextView. Pass it directly like this
[self presentModalViewController:redirectView animated:YES];
Add the line
[self.view addSubview:nextView];
instead of
[self presentModalViewController:self.nextView animated:YES];
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"];
}
精彩评论