判断当前页是否登录

2017-12-08  本文已影响52人  一笑wangx

判断当前的页面是否登录,如果登录直接显示数据,如果没有登录,就先登录(使用单力判断)
1.在单例.h中写@property(nonatomic,assign)BOOL isLogin;
+(instancetype)sharePerson;
2.在.m中写+(instancetype)sharePerson{
static id _instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc]init];
});
return _instance;
}
3.在APPdelegate中 WXFPPerson *person = [WXFPPerson sharePerson];
person.isLogin = isLogin;
保存登录状态
4.在进入该页面时判断 if(_person.isLogin)
{
VillageViewController *village = [[VillageViewController alloc] init];

        [self.navigationController pushViewController:village animated:YES];
        
    }else
    {
        LoginViewController *vc = [[LoginViewController alloc]init];
        self.view.window.rootViewController = vc;
    }
上一篇 下一篇

猜你喜欢

热点阅读