iOS5中关于dismissModalViewController的问题

  将项目转移至SDK5后出现不少问题。其中一个便是在sdk4下可以正常返回的dismissModalViewController,在sdk5下有部 分不起作用。大概原因是因为调用presentModalViewController的那个controller是放在 UINavigationController或者UITabbarViewController,没有具体测试。不过查看最新的sdk5文档。解决方案 如下:
view plain

1
2
3
4
5
// The view controller that was presented by this view controller or its nearest ancestor.  
@property(nonatomic,readonly) UIViewController *presentedViewController  __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);  
   
// The view controller that presented this view controller (or its farthest ancestor.)  
@property(nonatomic,readonly) UIViewController *presentingViewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);  


其中presentedViewController可以获取到由当前controller调用presentModalViewController展示的子视图。
presentingViewController则可以获取到展示当前controller的父级视图controller。
因此在ios5中可以在被展示的视图controller使用以下代码返回上一级视图:
view plain

1
[self.presentingViewController dismissModalViewController:YES];  


至于兼容多个版本的问题,请自己根据系统版本:
#ifndef IOS_VERSION
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#endif

原文地址:http://www.cocoachina.com/bbs/read.php?tid-79335.html
判断IOS_VERSION>=5.0进行代码兼容

原文地址:https://www.cnblogs.com/ligun123/p/2220037.html