2013-06-11 107 views
11

我得到在Xcode中警告:presentModalViewController:動畫已被棄用

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

在這行代碼:

[self presentModalViewController:initialSettingsVC animated:YES]; 

我試圖取代它成爲在documentation與建議:

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

我現在在XCode中出現錯誤:

爲 '視圖控制器' 不可見@interface聲明選擇 'presentModalViewController:動畫:完成:'

任何想法?

+1

您有拼寫錯誤的方法。它是'presentViewController:animated:completion'。刪除'Modal'。 – bbarnhart

+0

@bbarnhart你是對的。這是解決方案。 – poiuytrez

回答

4

你想使用以下

- (void)presentViewController:(UIViewController *)viewControllerToPresent 
         animated: (BOOL)flag completion:(void (^)(void))completion; 

爲了得到模態動畫/演示你正在尋找

12

使用以下settting UIModalPresentationStyleUIModalTransitionStyleviewController ....... 。

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

我發現Here

5

更換

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

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

截至ios 10,這不會做模態演示。 –