gpt4 book ai didi

ios - rootViewController 是否始终准备好在应用程序 :didBecomeActive is called (iOS)? 之前呈现 segue

转载 作者:行者123 更新时间:2023-11-28 18:46:46 25 4
gpt4 key购买 nike

我的应用程序在 Storyboard中设置了 rootViewController。我最初问这个问题,但我现在可以看出这是错误的问题:

Is the viewDidLoad method of the rootViewController always called before application:didBecomeActive in the app delegate? Does that viewDidLoad method always finish before application:didBecomeActive is called, or can the two run concurrently?

I can run tests, but I know that these tests don't take into account every situation. I want to understand if there are hard and fast rules that apply here, or if I might possibly be dealing with race conditions at some point. From what I can tell, viewDidLoad of the rootViewController seems to be called and finished before application:didbecomeActive is called, but I can't figure out if this is something I can rely on.

I am using iOS 11 and Xcode 9.

我的 rootViewController 用于显示我的 appUpdating View 、密码 View 、我的法律条款 View 、我的 handleImportedFile View 和我的 tabbarcontroller。它就像某种启动协调器,因为我的加载过程非常复杂。现在我正在移动用户的sqlite数据库的位置,我的一些用户的数据库很大。它必须在后台完成,但是当 hud 在主队列上运行时,因为在完成之前应用程序无法显示数据。如果我在 application:didFinishLaunchingWithOptions 期间执行此操作,一些用户将获得看门狗计时器。所以我想将加载过程移动到 application:didBecomeActive (我有一个标志告诉我应用程序是否从终止启动)。当它完成运行时,rootViewController 执行到相关 View 的 segue。但我认为 rootViewController 需要在那个时候加载,我不确定情况是否总是如此。

基本上,在下面的代码中,我试图弄清楚 [self.masterController showApplicableView] 是否在“安全的地方”,或者如果在任何情况下,此时让 rootViewController 执行 segue 可能为时过早。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.masterController = (MasterViewController*)self.window.rootViewController;
self.activatingFromTerminated = YES;

return YES;
}

- (void)applicationWillEnterForeground:(UIApplication *)application {

self.activatingFromTerminated = NO;
}

- (void)applicationDidBecomeActive:(UIApplication *)application {

if (_activatingFromTerminated) {

self.activatingFromTerminated = NO;

[[CoreDataController sharedManager] loadStoreWithCompletionHandler:^(NSError * _Nullable error) {

if ([CoreDataController sharedManager].storeLoaded) {

[self.masterController showApplicableView];//performs applicable segue
}
}];
}
}

最佳答案

From what I can tell, viewDidLoad of the rootViewController seems to be called and finished before application:didbecomeActive is called, but I can't figure out if this is something I can rely on.

它不是,你也不应该。你根本不应该担心这个。事实上,您认为您需要知道这是代码中的难闻气味。这些是来自两个完全不同区域(应用程序和 View Controller )的生命周期事件,它们的相对时间与您无关。在每个事件中做适合该事件意义的事情。

关于ios - rootViewController 是否始终准备好在应用程序 :didBecomeActive is called (iOS)? 之前呈现 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51884528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com