iOS 5:在 iPad 中关闭模式后不会调用 -viewWillAppear
我使用以下代码呈现模态:
AddName *add = [[AddName alloc] initWithNibName:@"AddName" bundle:nil]
add.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalView:add animated:YES];
在工作之后,我使用以下代码返回我的主视图。
[self dismissModalViewControllerAnimated:YES];
所以它默认调用-viewWillAppear
。
我的问题是,
它在 iOS4.3 上运行良好。
但它不适用于iOS5。
我应该怎么办 ?或者这是 iOS5 中的任何错误吗?
I am presenting modal using the following code :
AddName *add = [[AddName alloc] initWithNibName:@"AddName" bundle:nil]
add.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalView:add animated:YES];
And After my work I use following code to go back on my main view.
[self dismissModalViewControllerAnimated:YES];
So it use to call -viewWillAppear
by default.
My problem is that,
It was working fine with iOS4.3.
But Its not working with iOS5.
What should I do ? Or Is that any bug in iOS5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-viewWillAppear
仅保证在-viewWillDisappear
也被调用的地方被调用。对于 iPad 上的大多数模态窗口而言,情况并非如此,因为它们不会遮挡整个页面。问题的解决方案取决于您需要
-viewWillAppear
的用途,但一般来说,您可能需要直接从关闭模态视图控制器的同一位置进行调用。一种常见的机制,特别是在您可能在其他地方使用相同模态视图的情况下,是为模态视图控制器提供一个委托,该委托在视图即将消失时调用。这将使您有机会从模式窗口获取响应,甚至只是在委托视图中强制重新加载数据。
希望这有帮助。
-viewWillAppear
is only guaranteed to be called in places where the-viewWillDisappear
has also been called. For most modal windows on the iPad, this is not the case, since they don't obscure the entire page.The solution to your problem will depend on what you need the
-viewWillAppear
for, but in general, you're likely to need to make a call directly from the same place that you dismiss the modal view controller.One common mechanism for this, especially in cases where you might use that same modal view somewhere else, is to give the modal view controller a delegate which is called when the view is about to disappear. This will give you a chance to take the responses from the modal window, or even just force a data reload in the delegate view.
Hope this helps.
iOS 5 确实改变了对 viewWillAppear 和 viewWillDisappear 的调用。例如,
UIScrollView
中的子视图(View Controller 的视图
确切地说是子视图),当您将另一个视图控制器推入其中时,viewWillDisappear
将被调用堆栈。但是,当视图控制器弹出时,viewWillAppear
不会被调用。在 iOS 4 中,从未在UIScrollView
子视图上调用这些方法。这对我来说是奇怪的行为。再加上这样一个事实:无论会发生什么,如果你可以依赖它在 iOS 4 中发生的情况,那么它在 iOS 5 中的工作方式应该不会有所不同。大多数时候,我不知道每个实例在哪个特定实例中被调用,我通常会在区域编码时进行尝试和错误。如果事情按照我喜欢的方式进行,我就会继续前进。然后 iOS 5 出现了,给一切带来了破坏。
我也经历过,当 UINavigationController 的视图是子视图,并且 ViewController 被推送到导航控制器堆栈上时,viewWillAppear 永远不会在 iOS 中被调用4,但在 iOS 5 中确实会被调用。想想吧。
iOS 5 definitely changed their calls to
viewWillAppear
andviewWillDisappear
. For instance, subviews (View Controller's views
as subviews to be exact) in aUIScrollView
,viewWillDisappear
will get called when you push another view controller onto the stack. However, when the view controller is popped,viewWillAppear
does not get called. These methods were never called in iOS 4 onUIScrollView
subviews.This is strange behavior to me. Couple that with the fact that regardless of what should happen, if you could rely on it happening in iOS 4, it should not be working differently in iOS 5. Most of the time, I have no idea in which particular instance each one is called, I usually trial and error it as I'm in the zone coding. If it works the way I like, I move on. Then iOS 5 comes in and throws a wrecking ball into everything.
I have also experienced when a
UINavigationController's
view is a subview, and aViewController
is pushed on the navigation controller stack,viewWillAppear
never gets called in iOS 4, but does get called in iOS 5. Go figure.我也有同样的问题。
我发现在关闭模态后,
viewWillAppear
不会被调用,但viewDidAppear
会被调用。因此,只需尝试viewDidAppear
即可。I had the same problem.
I found that
viewWillAppear
isn't get called after dismissing modal butviewDidAppear
is. So just tryviewDidAppear
instead.