viewDidAppear,但是viewDidShowToUser在哪里?
我有一个 iphone3g,在我的 ViewController 中运行此功能,
- (void)viewDidAppear:(BOOL)animated {
[super viewDidLoad];
}
我使用 TabBar iphone 应用程序。但是,当我从选项卡 1 单击到选项卡 2 并调试 secondaryView Controller 时,它会在视图实际位于用户视图中之前停止。
因此,当您单击选项卡 2 直到 (void)viewDidAppear:(BOOL)animated 内的每个函数完成时,用户就可以看到视图。
ViewDidShowToUser函数在哪里?现在我正在运行一些功能,因此有时会很慢,并且您认为该按钮实际上不起作用。
I have an iphone3g with this function running in my ViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidLoad];
}
I use a TabBar iphone app. But when I click from tab 1 to tab 2 and debug the secondView Controller it is stopped before the view is actually in the users view.
So there for when you click tab 2 until every function inside - (void)viewDidAppear:(BOOL)animated is complete the user gets to see the view.
Where is the function ViewDidShowToUser? Now I have a few functions running so it's sometimes slow and you're thinking the button is not working really..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您在
-viewDidAppear:
的实现中调用[super viewDidLoad]
而不是[super viewDidAppear:animated]
其次,使用调试器和断点可以人工了解应用程序的行为方式。在实际使用中,用户不会注意到
-viewDidAppear:
方法在实际显示视图之前返回。真正的问题是您的工作需要很长时间才能完成,并使应用程序显得缓慢。您应该考虑异步执行工作,并且您有几个选项可以做到这一点。
在您的
viewDidAppear:
实现中,您可以使用performSelector:withObject:afterDelay:
对工作进行排队。此方法将立即返回并安排您的选择器在您指定的任何时间段内调用。如果您传递 0 作为延迟,它将排队等待在运行循环的下一次迭代中运行,从而有效地为您提供了一种从方法返回并保持用户界面响应的方法。如果您不以 iOS4 以下的任何目标为目标,则可以使用块,并利用 Grand Central Dispatch 的强大功能来安全、良好地完成您的工作。
First of all, you're calling
[super viewDidLoad]
instead of[super viewDidAppear:animated]
inside your implementation of-viewDidAppear:
Secondly, using the debugger and breakpoints gives an artificial view of how your app behaves. In real world usage, users aren't going to notice that the
-viewDidAppear:
method returns before actually showing the view.The real problem is your work that takes too long to complete and makes the app appear sluggish. You should consider performing the work asynchronously, and you have a couple of options to do that.
In your
viewDidAppear:
implementation you could useperformSelector:withObject:afterDelay:
to queue up the work. This method will return immediately and schedule your selector to be called in whatever time period you specify. If you pass 0 as the delay, it'll be queued up to run on the next iteration of the run loop, effectively giving you a way to return from the method and keep the user interface responsive.You could use blocks, if you're not targeting anything below iOS4, and harness the power of Grand Central Dispatch to thread out your work nice and safely.
您正在 viewDidAppear: 内部的 viewDidLoad: 上调用 super: ....将行
[super viewDidLoad];
更改为[super viewDidAppear:animated];
you are calling super on viewDidLoad: inside of viewDidAppear: ....change the line
[super viewDidLoad];
to[super viewDidAppear:animated];
没有简单的方法可以判断。
UIKit 制作 UIView。 UIViews 绘制到 CALayers。 CALayers 由 CoreAnimation 处理。
CoreAnimation 决定何时要求 UIView 绘制图层。它在屏幕上绘制所有图层,然后在 GPU 上合成它们。只有在它们合成后,屏幕才会显示更新后的 UI。发生这种解耦是为了允许 CoreAnimation 独立于 UI 线程完成大部分工作,但这意味着您无法轻松判断“实际在屏幕上”的内容。
没有简单的方法可以判断屏幕何时实际显示了某些内容(除了现在私有的 UIGetScreenImage() 之外)。 viewDidAppear:在 UIKit 完成视图/图层的构建(和动画)后被调用。此时,它们将在下一个运行循环后被 CoreAnimation“看到”,并在不久后显示。如果您在 viewDidAppear: 中进行大量处理,那么 CoreAnimation 将永远不会看到更新的“模型树”。
There's no easy way to tell.
UIKit makes UIViews. UIViews draw to CALayers. CALayers are handled by CoreAnimation.
CoreAnimation decides when to ask UIView to draw the layers. It draws all the layers on screen and then composites them on the GPU. Only after they're composited does the screen display the updated UI. This decoupling happens in order to allow CoreAnimation to do the majority of the work independently of the UI thread, but it means that you can't easily tell what's "actually on screen".
There is no easy way to tell when the screen has actually displayed something (apart from the now-private UIGetScreenImage()). viewDidAppear: gets called after UIKit finishes constructing (and animating) the views/layers. At that point, they will be "seen" by CoreAnimation after the next run loop, and displayed shortly thereafter. If you do lots of processing in viewDidAppear:, then CoreAnimation will never see the updated "model tree".