2025-03-25

5.0前後,對應的調用方法變瞭參數,而且如果用瞭5.0以後的方法在低版本上無法使用,而用低版本對用的方法,apple已經不提倡,現在有一種解決辦法

[cpp]
AboutViewController *mAboutViewController = [[AboutViewController alloc] initWithNibName:@"AboutViewController" bundle:nil]; 
 
        if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) { 
            [self.navigationController presentViewController:mAboutViewController animated:YES completion:nil]; 
        }else{ 
            [self.navigationController presentModalViewController:mAboutViewController animated:YES]; 
        } 
        [mAboutViewController release]; 
        mAboutViewController = nil; 

在調用時判斷一下

同理,dismiss時也是類似操作

[cpp]
if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) { 
            [self dismissViewControllerAnimated:YES completion:nil]; 
        }else{ 
            [self dismissModalViewControllerAnimated:YES]; 
        } 

以此類推,以後碰到類似,apple高版本sdk對低版本api不再支持時,可用類似判斷解決高低版本兼容問題。

 

摘自 安迪·潘 的專欄

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *