回覆回應

Behavior changed for parentViewController in iOS 5

Previously, if we present a modal view controller using:

[self presentModalViewController:modalViewController animated: YES]

We should able to get back the parent of the modal view controller using:

[modelViewController parentViewController]

and normally we will dismiss the view controller using:

[[modelViewController parentViewController] dismissModalViewControllerAnimated:YES];

However, after iOS 5, the behavior of parentViewController is changed, that it will return nil for the modal view controller. Instead, it's parent view controller can be given by the new accessor presentingViewController. i.e. the old parentViewController spited to parentViewController and presentingViewController

To fix the problem, I create the following defines:

#ifndef __presentingViewController
#define __presentingViewController(obj) (([obj respondsToSelector:@selector(presentingViewController)]) ? [obj presentingViewController] : [obj parentViewController] )
#endif //__presentingViewController//

Then we can use:
__presentingViewController(modelViewController)

instead of:
[modelViewController parentViewController]

Actually the dismiss a modal dialog, instead of:
[[modelViewController parentViewController] dismissModalViewControllerAnimated:YES];

we can simply called:

[modelViewController dismissModalViewControllerAnimated:YES];

so that we can avoid calling parentViewController in many cases.

回應

這個欄位的內容會保密,不會公開顯示。
  • 自動將網址與電子郵件位址轉變為連結。
  • 可使用的 HTML 標籤:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自動斷行和分段。
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.

更多關於格式選項的資訊

CAPTCHA
這條問題是測試你是否真正的人類使用者。
Image CAPTCHA
Enter the characters shown in the image.