我想根据用户状态(即 NSUserDefaults 值)切换场景,所以我使用了两个视图控制器和 segue。但它不起作用。我相信我的代码有问题。请帮忙。谢谢。
- (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");
}
}