How to set parentViewController in UIViewController?

前端 未结 6 826
春和景丽
春和景丽 2021-02-13 10:26

The parentViewController property of UIViewController is readonly, but I am nesting custom view controllers and would like to use this property.

However, since it is re

6条回答
  •  醉梦人生
    2021-02-13 10:53

    I realize this question was asked before iOS 5, but for the reference, you should use addChildViewController when you want to nest UIViewControllers. This will also automatically set the parentViewController property.

    - (void)addChildViewController:(UIViewController *)childController NS_AVAILABLE_IOS(5_0);
    

    You can read more about "Creating Custom Content View Controllers" at Apple.

提交回复
热议问题