(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self initView];
SetRootViewControllerHandle *handle = [[SetRootViewControllerHandle alloc] init];
[handle setRootViewController];
}
源代码是这样定义的,创建的临时变量;在SetRootViewControllerHandle.m文件中的方法实现如下-
(void)setRootViewController
{
if (self.isLogin) {// 登录状态
[self.viewModel initNetWorkOfGetUserInfo];} else {// 非登录状态
LoginViewController *VC = [[LoginViewController alloc] init];
VC.openType = OpenTypeRoot;
BaseNavigationController *naviC = [[BaseNavigationController alloc] initWithRootViewController:VC];
AppDelegateInstance.window.rootViewController = naviC;
}
}
在登录状态下,直接网络请求数据后在进行视图控制器的变换操作,但是SetRootViewControllerHandle是临时变量,代码运行后就直接销毁了,但是网络请求是异步操作,就导致网络请求的对象提前释放,导致的结果闪退或者无反应,所以不应该定义为临时变量
@property (nonatomic,strong) SetRootViewControllerHandle *handle;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self initView];
self.handle = [[SetRootViewControllerHandle alloc] init];
[self.handle setRootViewController];
}
增加对象的持有时间就好了咯