当前位置:编程学习 > wap >>

(iPhone/iPad开发)presentViewController相应方法在SDK5.0前后变化后通用方法

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不再支持时,可用类似判断解决高低版本兼容问题。

 


摘自 安迪·潘 的专栏

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,