【发布时间】:2014-09-07 18:10:00
【问题描述】:
我正在使用 modal segue(没有导航控制器)在 viewController A 和 viewController B 之间移动,如下所示:
viewA *first = [self.storyboard instantiateViewControllerWithIdentifier:@"viewA"];
[self presentViewController:first animated:YES completion:nil];
然后向后移动:
[self dismissViewControllerAnimated:YES completion:nil];
现在,我想从 AppDelegate 知道 A 还是 B 是当前视图。 问题是当我检查时
[(AppDelegate *)[[UIApplication sharedApplication] delegate] window]
答案始终是视图 A - 第一个。
每次使用模态转场时,我都尝试设置当前视图,如下所示:
viewA *first = [self.storyboard instantiateViewControllerWithIdentifier:@"viewA"];
[self presentViewController:first animated:YES completion:^
{
[[(AppDelegate *)[[UIApplication sharedApplication] delegate] window] setRootViewController:first];
}];
但这会导致一些错误(例如无法使用“dismissViewControllerAnimated”),并且不可能在具有许多segue的大项目中的每个segue中都这样工作。
我应该如何处理它?以及我应该如何以更合适的方式检测当前视图?
【问题讨论】:
标签: ios objective-c uiviewcontroller