2012-09-28 203 views
23

我剛剛更新了iOS 6,並運行了我在iOS 4.3中創建的舊代碼。他們在我的申請中給了我一些警告。dismissmodalviewcontrolleranimated已棄用ios 6首先棄用

我用presentModelViewController:,然後我解僱了,但它給了我警告

dismissModalViewControllerAnimated is deprecated first deprecated in iOS 6.

他們爲什麼會顯示警告該代碼?以下是代碼:

[picker dismissModalViewControllerAnimated:YES]; 

此行變黃並顯示錯誤。請給我指引以刪除警告。

+2

閱讀文檔的UIViewController ,他們會告訴你用什麼來代替 – wattson12

+0

給你創建'picker' ViewController的代碼以及如何:) – 2012-09-28 13:29:38

回答

2

您可以使用dismissViewControllerAnimated:completion,從iOS Developer文檔

dismissViewControllerAnimated:completion:

Dismisses the view controller that was presented by the receiver. - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion Parameters

flag

Pass YES to animate the transition. completion 

A block called after the view controller has been dismissed. 

Discussion

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, it automatically forwards the message to the presenting view controller.

If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

If you want to retain a reference to the receiver’s presented view controller, get the value in the presentedViewController property before calling this method.

The completion handler is called after the viewDidDisappear: method is called on the presented view controller. Availability

Available in iOS 5.0 and later. 
+0

感謝您的指導,..它的作品很好。我可以問你一個問題嗎?爲什麼他們的使用「完成:(void(^)(void))完成」, – Piyush

+0

是「視圖控制器被解僱後調用的塊」 – ChristianD

59

現在在iOS 6中您可以使用

[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil]; 

而不是

[[Picker parentViewControl] dismissModalViewControllerAnimated:YES]; 

[self presentViewController:picker animated:YES completion:nil]; 

而不是

[self presentModalViewController:picker animated:YES]; 
4

如果你的部署目標設置到iOS 6,那麼我會檢查你的部署目標,這可能是設置爲默認的Xcode您應該只得到棄用警告。一旦將其更改爲4.3,棄用警告應該消失。

2

我改變我的代碼

[self dismissModalViewControllerAnimated:YES]; 

[self dismissViewControllerAnimated:YES]; 

和接收錯誤: 爲 'KLPARewardController' 不可見@interface聲明選擇 'dismissViewControllerAnimated:'