久久久久久久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,這是創建自定義視圖控制器容器的能力,類似于 UITabBarControllerUINavigationController 等.

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 消失了)
主站蜘蛛池模板: 盗摄精品av一区二区三区 | 欧美日韩久久久久 | 亚洲综合在线视频 | 一区二区三区在线观看视频 | 国产2区 | 在线播放国产一区二区三区 | 日韩电影在线 | av在线电影网站 | 精品九九久久 | 操操操av| 欧美极品在线视频 | 正在播放一区二区 | 国产精品毛片一区二区在线看 | 91视频在线网站 | 精品欧美激情精品一区 | 久久亚洲一区二区 | 亚洲欧美日韩精品久久亚洲区 | 一区二区三区在线看 | 国产国产精品久久久久 | 亚洲一区二区三区免费视频 | 秋霞av国产精品一区 | 国产精品国产三级国产aⅴ浪潮 | 在线国产99 | 91色在线| 亚洲国产成人精品在线 | 成年人免费看的视频 | 成人av在线播放 | 亚洲 欧美 日韩在线 | 91在线中文字幕 | 中文日韩在线视频 | 噜久寡妇噜噜久久寡妇 | 久久精品亚洲国产 | 久久精品视频网站 | 全部免费毛片在线播放网站 | 成人在线小视频 | 久色一区 | 国产福利资源在线 | 国产一区二区精品在线 | 黄色一级大片在线免费看产 | 国产激情综合五月久久 | 欧美国产日韩在线 |