久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

視圖控制器包含在 iOS 5 中是如何工作的?

How does View Controller Containment work in iOS 5?(視圖控制器包含在 iOS 5 中是如何工作的?)
本文介紹了視圖控制器包含在 iOS 5 中是如何工作的?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

在 WWDC 2011 Session 102 中,Apple 引入了 View Controller Containment,這是創建自定義視圖控制器容器的能力,類似于 UITabBarController、UINavigationController 等.

In WWDC 2011 Session 102, Apple introduced View Controller Containment, which is the ability to create custom view controller containers, analogous to UITabBarController, UINavigationController, and the like.

我看了好幾遍這些例子.有很多與這種模式相關的方法,但要準確地找出它們有點困難.我將在這里發布我的想法,看看社區是否會證實或否定我的懷疑.

I watched the examples several times. There are a flurry of methods associated with this pattern, but it was a little hard to figure them out exactly. I'm going to post here what I think is going on and see if the community will confirm or disconfirm my suspicions.

場景 1:從無父視圖控制器移動到新的父視圖控制器

[vc willMoveToParentViewController:self];
[self addChildViewController:vc];
[self.view addSubview:vc.view]; // or something like this.
[vc didMoveToParentViewController:self];

前兩行是否必須按照給定的順序出現,還是可以顛倒?

Do the first two lines have to occur in the order given, or can they be reversed?

場景 2:從父視圖控制器移動到無父視圖控制器

[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];

是否也需要調用[vc didMoveToParentViewController:nil]?Session 102 中的示例在這種情況下沒有這樣做,但我不知道這是否是一個遺漏.

Is it also necessary to call [vc didMoveToParentViewController:nil]? The examples in Session 102 did not do this in this scenario, but I don't know whether that was an omission or not.

場景 3:從一個父視圖控制器移動到另一個

這很可能會發生在下面的方式中,因為每個父視圖控制器中的邏輯都會被封裝.

This will likely occur in the following way, because the logic in each parent view controller will be encapsulated.

// In the old parent
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];

// In the new parent
[vc willMoveToParentViewController:self];
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[vc didMoveToParentViewController:self];

問題

我的主要問題是:一般來說,視圖控制器包含應該如何工作?上面給出的機制正確嗎?

My main question is this: Is this how view controller containment should work, in general? Are the mechanics given above correct?

在調用addChildViewController之前需要調用willMoveToParentViewController嗎?這對我來說似乎是合乎邏輯的順序,但這是絕對必要的嗎?

Is it necessary to call willMoveToParentViewController before calling addChildViewController? This seems like the logical order to me, but is it strictly necessary?

是否需要在調用removeFromParentViewController之后再調用didMoveToParentViewController:nil?

Is it necessary to call didMoveToParentViewController:nil after calling removeFromParentViewController?

推薦答案

UIViewController 文檔非常清楚何時以及何時不調用 willMove/didMove 方法.查看 實現容器視圖控制器" 文檔.

The UIViewController docs are pretty clear on when and when not to call willMove/didMove methods. Check out the "Implementing a Container View Controller" documentation.

文檔說,如果您不覆蓋 addChildViewController,則不必調用 willMoveToParentViewController: 方法.但是,您確實需要在轉換完成后調用 didMoveToParentViewController: 方法.同樣,容器視圖控制器有責任在調用 removeFromParentViewController 方法之前調用 willMoveToParentViewController: 方法.removeFromParentViewController 方法調用子視圖控制器的 didMoveToParentViewController: 方法."

The docs say, that if you do not override addChildViewController, you do not have to call willMoveToParentViewController: method. However you do need to call the didMoveToParentViewController: method after the transition is complete. "Likewise, it is is the responsibility of the container view controller to call the willMoveToParentViewController: method before calling the removeFromParentViewController method. The removeFromParentViewController method calls the didMoveToParentViewController: method of the child view controller."

另外,還有一個例子 這里和示例代碼這里.

Also, there is an example worked out here and sample code here.

祝你好運

這篇關于視圖控制器包含在 iOS 5 中是如何工作的?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Using Instruments to test an iOS app without having source code to the application(在沒有應用程序源代碼的情況下使用 Instruments 測試 iOS 應用程序)
KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動運行/壓力測試 iOS 應用程序以找出罕見 UI 錯誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態和動態單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級到 Xcode 4.5 后,iOS 5 SDK 消失了)
主站蜘蛛池模板: 日韩久久中文字幕 | 国产精品欧美精品 | 精品综合久久久 | 人人九九精 | 日韩免费一区二区 | 91福利影院 | 九九亚洲 | 中文字字幕在线中文乱码范文 | 国产一在线观看 | 在线视频一区二区三区 | 中文字幕精品一区 | 亚洲欧美日韩在线 | 亚洲欧美日韩中文字幕一区二区三区 | 国产专区在线 | 精品欧美一区二区三区精品久久 | 国产福利在线视频 | av中文在线播放 | 91爱爱·com| 亚洲精品9999| 欧美不卡视频一区发布 | 国产乱码精品一区二区三区五月婷 | 成人妇女免费播放久久久 | 在线观看中文字幕一区二区 | 黑人巨大精品欧美一区二区免费 | 伊人伊人伊人 | 欧美成人免费电影 | 久久久精 | 99精品视频免费观看 | 亚洲国产成人精品久久久国产成人一区 | 伊人伊人 | 日韩精品免费视频 | 欧美精品综合在线 | 99草免费视频 | 91免费视频观看 | 久久久噜噜噜久久中文字幕色伊伊 | 色姑娘av| 国产激情在线播放 | 亚洲天堂男人的天堂 | japanhd成人 | 亚洲不卡在线观看 | 国产激情精品视频 |