//点击退出系统按钮时
-(void)didClickLogoutBtn{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"您确定要退出吗"delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"退出" otherButtonTitles:nil, nil];
[actionSheet showInView:self.view];
}
//实现UIActionSheet的代理
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
//退出系统,返回登陆界面(从storyboard里加载的)
UIStoryboard *mainStory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//storyboard里的ID
UIViewController *vc = [mainStory instantiateViewControllerWithIdentifier:@"Login"];
//设置当前窗口的根控制器
self.view.window.rootViewController = vc;
}
}
注意:UIWindow *window = [UIApplication sharedApplication].keyWindow;
通过获取这个window,然后改变window.rootViewController 不正确。他会跳转一下有跳转到别的界面,不知道具体原因。。。