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/archive/2011/10/21/2220037.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值