How to set parentViewController in UIViewController?

前端 未结 6 829
春和景丽
春和景丽 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:51

    Solution is:

       - (void)setParentController:(UIViewController*)parent{
     [self setValue:parent forKey:@"_parentViewController"];
        }
    

    It does not cause problems with linker!

    PS: Don't use "setParentViewController" as method name, because this method exists in private API and Apple say: "The non-public API that is included in your application is setParentViewController:.

    If you have defined a method in your source code with the same name as the above mentioned API, we suggest altering your method name so that it no longer collides with Apple's private API to avoid your application being flagged with future submissions.

    Please resolve this issue in your next update..."

提交回复
热议问题