gpt4 book ai didi

iphone - viewDidAppear : called twice on modal view controller presented during startup

转载 作者:行者123 更新时间:2023-12-03 21:00:34 24 4
gpt4 key购买 nike

解决方案:在尝试在新项目中重新创建此错误以提交给 Apple 时,我发现它特定于 iPhone OS 2.1,并且编译 2.2 修复了该问题。斯蒂芬,谢谢你的帮助;我会接受你的答案,因为如果 bug 仍然存在或者我不愿意编译 2.2,它就会起作用。

<小时/>

我有一个应用程序正在从根本上改变其数据库模式,要求我在代码中将旧式记录转换为新式记录。由于用户可能在此应用程序中存储大量数据,因此我尝试在传输数据时显示带有进度条的模态视图 Controller (即,作为用户看到的第一件事)。该 View Controller 的 viewDidAppear: 开始一个数据库事务,然后启动一个后台线程来执行实际的移植,偶尔会使用performSelectorInMainThread:withObject:waitUntilDone: 告诉前台线程更新进度条。

问题是,viewDidAppear: 被调用了两次。我注意到这一点是因为“启动事务”步骤失败并显示“数据库繁忙”消息,但设置断点表明它确实被调用了两次 - 一次由 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] ,并再次通过 -[UIViewController modalPresentTransitionDidComplete]。这些名称似乎是私有(private) UIViewController 方法,所以我猜测这要么是一个框架错误,要么我正在做一些 UIKit 不希望我做的事情。

两段相关代码摘录(已经总结了一些不相关的代码):

- (void)applicationDidFinishLaunching:(UIApplication *)application {
(register some default settings in NSUserDefaults)

// doing this early because trying to present a modal view controller
// before the view controller is visible seems to break it
[window addSubview:[self.navigationController view]];

// this is the method that may present the modal view
[self.databaseController loadDatabaseWithViewController:self.navigationController];

if(!self.databaseController.willUpgrade) {
[self restoreNavigationControllerState];
}
}

来 self 的 DatabaseController 类:

- (void)loadDatabaseWithViewController:(UIViewController*)viewController {
(open the new database)

(compute the path the old database would live at if it existed)

if([[NSFileManager defaultManager] fileExistsAtPath:oldDBPath]) {
(open the old database)

[viewController presentModalViewController:self animated:NO];
}
}

那么,我是否搞砸了一些事情,或者我应该向 Apple 提交错误报告?

最佳答案

我也在我的应用程序中看到了这个。我从未得到完全证实,但我认为这就是正在发生的事情:

  1. 加载 Root View
  2. 加载模态视图
  3. 操作系统在步骤 1 中发送 View 确实出现通知
  4. 当前 View Controller (在本例中恰好是您的 DatabaseController 类)会选择它
  5. 操作系统发送模态视图的 View 确实出现通知
  6. 当前 View Controller 收到通知。在本例中,它与上次完全相同的 Controller

就我而言,我只是重置了第一次调用 viewDidAppear: 时发生的情况。

在您的情况下,我会想到两个选项:一个静态变量来跟踪您是否已经开始升级;或者查看启动前传入的UIView*参数。

关于iphone - viewDidAppear : called twice on modal view controller presented during startup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/619269/

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