简体   繁体   English

在ios 6中首先弃用dismissmodalviewcontrolleranimated

[英]dismissmodalviewcontrolleranimated is deprecated first deprecated in ios 6

I have just updated iOS 6, and run my old code, which is created in iOS 4.3. 我刚刚更新了iOS 6,并运行了我在iOS 4.3中创建的旧代码。 They give me number of warnings in my application. 他们在我的申请中给了我一些警告。

I used presentModelViewController: and then I dismiss it, but it gave me warning 我使用了presentModelViewController:然后我解雇了它,但它给了我警告

dismissModalViewControllerAnimated is deprecated first deprecated in iOS 6. 不推荐使用dismissModalViewControllerAnimated在iOS 6中弃用。

Why they show warning to that code? 为什么他们会对该代码发出警告? Here is the code: 这是代码:

[picker dismissModalViewControllerAnimated:YES];

This line gets yellow and show the error. 此行变为黄色并显示错误。 Please give me guideline to remove the warning. 请给我指导删除警告。

Now in ios 6 You can use 现在在ios 6你可以使用

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

Instead of 代替

[[Picker parentViewControl] dismissModalViewControllerAnimated:YES];

and

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

Instead of 代替

[self presentModalViewController:picker animated:YES];

You should only get the deprecation warning if your deployment target is set to iOS 6. So I would check your deployment target, which is probably set to the Xcode default. 如果部署目标设置为iOS 6,则只应获取弃用警告。因此,我会检查您的部署目标,该目标可能设置为Xcode默认值。 Once you change this to 4.3 the deprecation warnings should disappear. 将此更改为4.3后,弃用警告应消失。

You can use dismissViewControllerAnimated:completion , from the iOS Developer docs 您可以在iOS Developer文档中使用dismissViewControllerAnimated:completion

dismissViewControllerAnimated:completion: dismissViewControllerAnimated:完成:

Dismisses the view controller that was presented by the receiver. 解散接收器呈现的视图控制器。 - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion Parameters - (void)dismissViewControllerAnimated:(BOOL)标志完成:(void(^)(void))完成参数

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. 如果要保留对接收者呈现的视图控制器的引用,请在调用此方法之前获取presentViewController属性中的值。

The completion handler is called after the viewDidDisappear: method is called on the presented view controller. 在呈现的视图控制器上调用viewDidDisappear:方法之后调用完成处理程序。 Availability 可用性

 Available in iOS 5.0 and later. 

I change my code 我改变了我的代码

[self dismissModalViewControllerAnimated:YES];

to

[self dismissViewControllerAnimated:YES];

and receive error: No visible @interface for 'KLPARewardController' declares the selector 'dismissViewControllerAnimated:' 并收到错误:'KLPARewardController'没有可见的@interface声明选择器'dismissViewControllerAnimated:'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM