5.多个Storyboard切换

通知中心 注册通知中心监控用户登录状态

1.定义一个方法

  -(void)registerNotification{

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

    //参数说明: 1.通知中心监听者 2.发生通知时调用的选择器方法 3.发生的通知名称 4.传递给选择器方法的对象

    [center addObserver:self selector:@selector(loginStateChange) name:kNotificationUserLogonState object:nil];

  }

  定义一个常量  #define kNotificationUserLogonState @“kNotificationUserLogon”

  -(void)loginStateChange{  //选择器方法

    // 登录成功后执行。。。

    }  

在登录成功的地方调用方法

  [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationUserLogonState object:nil];

  

2.在AppDelegate.h中 添加一个属性

//用是否登录成功  @property (assign, nonatomic)BOOL isUserLogon;

  在身证验证通过方法  用户上线之前 添加 _isUserLogon = YES;

在到 loginStateChange 方法中判断_isUserLogon进入那个storyboard.

-(void)loginStateChange{

  UIStoryboard *storyboard = nil;

  if(_isUserLogon){storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];}

  else{storyboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];}

//把Storyboard的初始视图控制器设置为window的rootViewController

  [self.window setRootViewController:storyboard.instantiateInitalViewController];

}

原文地址:https://www.cnblogs.com/qq907374866/p/4253003.html