dismissmodalviewcontrolleranimated已弃用ios 6首先弃用

问题描述:

我刚刚更新了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

您可以使用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

现在在iOS 6中您可以使用

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

而不是

[[Picker parentViewControl] dismissModalViewControllerAnimated:YES]; 

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

而不是

[self presentModalViewController:picker animated:YES]; 

如果你的部署目标设置到iOS 6,那么我会检查你的部署目标,这可能是设置为默认的Xcode您应该只得到弃用警告。一旦将其更改为4.3,弃用警告应该消失。

我改变我的代码

[self dismissModalViewControllerAnimated:YES]; 

[self dismissViewControllerAnimated:YES]; 

和接收错误: 为 'KLPARewardController' 不可见@interface声明选择 'dismissViewControllerAnimated:'