原来的应用在iOS5下做了调试,发现一个弹出的模式窗口的parentViewController属性一直返回nil,查了一下Apple的文档,发现iOS5下UIViewController的parentViewController属性已经发生了变化,所有模式窗口的parentViewController属性都会返回nil,要获得模式窗口的父窗口,需要使用新的presentingViewController属性,同时增加的还有presentedViewController属性,对应用来获取子窗口。
相关的Apple SDK说明如下(注意红色的字):
parentViewController
The parent of the current view controller. (read-only)
@property(nonatomic, readonly) UIViewController *parentViewController
Parent view controllers are relevant in navigation, tab bar, and modal view controller hierarchies. In each of these hierarchies, the parent is the object responsible for displaying the current view controller. If you are using a view controller as a standalone object—that is, not as part of a view controller hierarchy—the value in this property is nil.
Prior to iOS 5.0, if a view did not have a parent view controller and was being presented modally, the view controller that was presenting it would be returned. This is no longer the case. You can get the presenting view controller using the presentingViewController property.
Available in iOS 2.0 and later.
presentedViewController
The view controller that was presented by this view controller, or one of its ancestors. (read-only)
@property(nonatomic, readonly) UIViewController *presentedViewController
Available in iOS 5.0 and later.
presentingViewController
The view controller that presented this view controller. (read-only)
@property(nonatomic, readonly) UIViewController *presentingViewController
The default implementation of this property walks up the view hierarchy, starting from this view controller. The first view controller it finds that received the presentViewController:animated:completion: method, or that has its definesPresentationContext property set to YES is returned as the value of the property. It keeps walking up the hierarchy until it finds a value to return or it gets to the root view controller.
Available in iOS 5.0 and later.
相关的Apple SDK说明如下(注意红色的字):
parentViewController
The parent of the current view controller. (read-only)
@property(nonatomic, readonly) UIViewController *parentViewController
Parent view controllers are relevant in navigation, tab bar, and modal view controller hierarchies. In each of these hierarchies, the parent is the object responsible for displaying the current view controller. If you are using a view controller as a standalone object—that is, not as part of a view controller hierarchy—the value in this property is nil.
Prior to iOS 5.0, if a view did not have a parent view controller and was being presented modally, the view controller that was presenting it would be returned. This is no longer the case. You can get the presenting view controller using the presentingViewController property.
Available in iOS 2.0 and later.
presentedViewController
The view controller that was presented by this view controller, or one of its ancestors. (read-only)
@property(nonatomic, readonly) UIViewController *presentedViewController
Available in iOS 5.0 and later.
presentingViewController
The view controller that presented this view controller. (read-only)
@property(nonatomic, readonly) UIViewController *presentingViewController
The default implementation of this property walks up the view hierarchy, starting from this view controller. The first view controller it finds that received the presentViewController:animated:completion: method, or that has its definesPresentationContext property set to YES is returned as the value of the property. It keeps walking up the hierarchy until it finds a value to return or it gets to the root view controller.
Available in iOS 5.0 and later.