UIViewController 在更新期间冻结
我的主 UIViewController 应该在加载时检查一些数据更新,如果发现任何更新,则会添加不透明的子视图以显示进度等。
假设该方法称为 checkUpdates,因此在我的应用程序委托中我执行以下操作:
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[viewController checkUpdates];
该方法就像
- (void) checkUpdates {
// add the opaque progress view
[self.view addSubview:progress.view];
[progress setMessage: @"Checking for updates ..."];
// ... perform the update ...
// remote the progress view
[progress.view removeFromSuperview];
}
理论上应该加载视图并且应该看到更新过程,但问题是视图在此阶段被冻结,当更新过程完成后,我就可以与其进行交互。
有什么想法吗?
my main UIViewController should check for some data updates when it loads, if any update is found an opaque subview is added to show progress and so on.
Let's say that the method is called checkUpdates, so in my app delegate i do the following:
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[viewController checkUpdates];
The method is like
- (void) checkUpdates {
// add the opaque progress view
[self.view addSubview:progress.view];
[progress setMessage: @"Checking for updates ..."];
// ... perform the update ...
// remote the progress view
[progress.view removeFromSuperview];
}
Theoretically the view should load and the update process should be seen, but the problem is that the view just get freezed during this phase, and when the update process is finished i'm able to interact with it.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 UI 运行在应用程序的主线程上,如果您在主线程上执行“工作”任务,您也会阻塞 UI,因此看起来会冻结。
您可能需要考虑使用
NSOperationQueue
或相当于分派另一个线程来完成您的工作,以便 UI 可以继续独立处理更新。Since the UI runs on the main thread of the app, if you perform "work" tasks on the main thread, you will also block the UI, which will therefore look frozen.
You might want to consider using
NSOperationQueue
or something equivalent to spin off another thread to do your work so the UI can continue to process updates independently.