presentModalViewController:animated已被弃用。

11

我在XCode中收到了一个警告:

'presentModalViewController:animated:' is deprecated: first deprecated in iOS 6.0

在这行代码上:

[self presentModalViewController:initialSettingsVC animated:YES];

我尝试按照文档中建议的进行替换:

[self presentModalViewController:initialSettingsVC animated:YES completion:nil];

我现在在XCode中遇到一个错误:

'ViewController'没有声明选择器'presentModalViewController:animated:completion:'

有任何想法吗?


1
您拼写的方法有误。正确的方法是 presentViewController:animated:completion。请删除“Modal”。 - bbarnhart
@bbarnhart 您是正确的。这就是解决方案。 - poiuytrez
3个回答

11

请使用以下代码来实现所需功能:

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]){
    [self presentViewController:test animated:YES completion:nil];
} else {
    [self presentModalViewController:test animated:YES];
}

我在这里找到了答案。


6
替换
[self presentModalViewController:initialSettingsVC animated:YES completion:nil];

To

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

1
从iOS 10开始,这将不会进行模态展示。 - Alex Sharp

4
你想使用以下内容:
- (void)presentViewController:(UIViewController *)viewControllerToPresent 
                      animated: (BOOL)flag completion:(void (^)(void))completion;

为了获得你想要的模态动画/呈现效果,需要设置viewControllerUIModalPresentationStyleUIModalTransitionStyle


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接