問題描述
我正在使用以下代碼呈現模態:
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];
所以默認調用-viewWillAppear
.
我的問題是,
在 iOS4.3 上運行良好.
但它不適用于 iOS5.
我該怎么辦?或者這是 iOS5 中的任何錯誤嗎?
What should I do ? Or Is that any bug in iOS5?
推薦答案
-viewWillAppear
只保證在 -viewWillDisappear
也被調用的地方被調用.對于 iPad 上的大多數模式窗口,情況并非如此,因為它們不會遮擋整個頁面.
-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.
您的問題的解決方案將取決于您需要 -viewWillAppear
來做什么,但一般來說,您可能需要直接從您關閉模式的同一個地方撥打電話視圖控制器.
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.
希望這會有所幫助.
這篇關于iOS 5:在 iPad 中關閉模式后不調用 -viewWillAppear的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!