我想根据用户状态(NSUserDefaults值)切换场景,所以我使用两个视图控制器和segues。但它没有用。我相信我的代码有问题。请帮忙。谢谢。
- (void)viewDidLoad
{
//sleep(5);
NSString *usercode = [[NSUserDefaults standardUserDefaults] objectForKey:@"usercode"];
if([usercode isEqualToString:@""] || usercode == nil){
[self performSegueWithIdentifier:@"loginSegue" sender:self];
NSLog(@"usercode start: key=%@", usercode);
}else{
[self performSegueWithIdentifier:@"loggedInSegue" sender:self];
NSLog(@"usercode start: not null key=%@", usercode);
}
[super viewDidLoad];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"loginSegue"])
{
NSLog(@"delegated");
//loginViewController *loginController = [segue destinationViewController];
NSLog(@"%@", NSStringFromClass([[segue destinationViewController] class]));
//controller.delegate=self;
}else if ([[segue identifier] isEqualToString:@"loggedInSegue"]){
NSLog(@"logged in delegated");
}
}
答案 0 :(得分:1)
应该在
-(void)viewDidAppear
而不是
-(void)viewDidLoad.