在运行过程中更改根控制器的方法:(假设:A为当前根控制器,B为要设的根控制器)
方法一:
1. appdelegate.m中
2. A.m中添加设置,比如一个按钮跳转到B并在B中设置B为根控制器
事件如下:
3. 注意点出来了,如果使用的是presentViewController则在设置B为根控制器的方法就必须在viewDidLoad与viewW
方法一:
1. appdelegate.m中
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
A *vc = [[A alloc] init]; // init会执行viewDidLoad viewWillAppear
vc.view.backgroundColor = [UIColor redColor];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
2. A.m中添加设置,比如一个按钮跳转到B并在B中设置B为根控制器
事件如下:
- (void)btnClick:(UIButton *)sender {
B *second = [[B alloc] init];
second.view.backgroundColor = [UIColor blueColor];
[self presentViewController:second animated:YES completion:nil];
// [self.view.window insertSubview:second.view aboveSubview:self.view];
}
3. 注意点出来了,如果使用的是presentViewController则在设置B为根控制器的方法就必须在viewDidLoad与viewW