标签:dismiss viewdidappear ios controller chain
我们的APP从启动到进入主页面,是通过presentViewController构造了一个ViewController序列,类似于首页 -> 登陆页 -> 启动加载页 -> 主页面
其中,在启动加载页的viewDidAppear方法里做了很多逻辑处理:
-(void) viewDidAppear:(BOOL)animated{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ clientInfo = [YLSClientInfo new]; if([clientInfo needInit]){ [self mkdirAndDatabaseFile]; }else{ [self refreshVersion:[clientInfo currentVersion]]; } // 各种处理逻辑 }); }
UIViewController *origin = self.presentingViewController.presentingViewController; if([origin isMemberOfClass:[YLSLoginViewController class]]){ origin = self.presentingViewController.presentingViewController.presentingViewController; } [origin dismissViewControllerAnimated:NO completion:nil];
查了一下API,又上stackoverflow搜索了半天,似乎没有办法阻止这个默认行为。所以最后我的解决办法是在中间的Controller上加了标记:
-(void) viewDidAppear:(BOOL)animated{ // 如果是由于调用了dismiss而触发了此方法,不进行初始化 if(self.isDismissing){ return; } // 初始化加载逻辑 }
YLSBootstrapViewController *bootstrapController = (YLSBootstrapViewController*)self.presentingViewController; bootstrapController.isDismissing = YES; UIViewController *origin = self.presentingViewController.presentingViewController; if([origin isMemberOfClass:[YLSLoginViewController class]]){ origin = self.presentingViewController.presentingViewController.presentingViewController; } [origin dismissViewControllerAnimated:NO completion:nil];
ios调用dismissViewController的一个小陷阱
标签:dismiss viewdidappear ios controller chain
原文地址:http://blog.csdn.net/kyfxbl/article/details/41991269