以下代码可以工作,但存在一个bug。场景是这样的:我首先登录进入应用程序系统。一旦登录成功,应用程序将设置UserDefaults(UserId)。之后,我可以使用存储的UserId导航应用程序视图。当我进入设置并点击注销时,它将清除UserId并跳转到登录视图。
BUG: 当我再次登录到应用程序并单击主屏幕按钮返回iPhone桌面并关闭应用程序,然后再次打开它时,它仍会存储UserId。因此,如果我进入设置并注销,它将清除UserId并不会跳转到登录视图。我不知道为什么。
代码:
BUG: 当我再次登录到应用程序并单击主屏幕按钮返回iPhone桌面并关闭应用程序,然后再次打开它时,它仍会存储UserId。因此,如果我进入设置并注销,它将清除UserId并不会跳转到登录视图。我不知道为什么。
代码:
- (IBAction)resetKeychain:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure you want to logout?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"Logout"
otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
[actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex ==0) {
//logout
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
//delete user ID fro user Defaults
[defaults setObject:nil forKey:@"UserId"];
//redirect to login view
NewClassMoonAppDelegate * appsDelegate =[[UIApplication sharedApplication] delegate];
[appsDelegate.window addSubview:[appsDelegate.login view]];
}
}