我目前正在初始屏幕上加载有关应用加载的数据。这发生在我的 viewWillAppear 中。我还有一个在此屏幕上弹出的模式,关闭时执行与在 viewWillAppear 中加载数据相同的逻辑。
如何只在应用程序打开时加载数据,而不是在模式关闭时加载?
最佳答案
UIViewController
提供了确定这一点的方法:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([self isBeingPresented] || [self isMovingToParentViewController]) {
// being presented or pushed
} else {
// showing again because another VC was dismissed
}
}
关于ios - 确定 viewWillAppear 是来自打开应用程序还是取消选择模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25985060/