UIViewController 与加载其中的View之间的相互引用

来源:互联网 发布:最小的linux 编辑:程序博客网 时间:2024/05/17 06:20

    UIViewController中,自定义UIView进行加载,将控制器的对象传递到View中需要进行weak弱引用,不然会产生引用循环,具体原因不太清楚,有待研究,可能是我代码的特殊环境造成的。

    例:在控制器中:

    CustomView * view  =  [[CustomView alloc]initWithFrame:frame Controller:self];

    [self.view addSubViews: view];

    

    在自定义的View中:

    @property (nonatomic, weak) UIViewController * controller;

    - (instancetype)initWithFrame:(CGRect)frame Controller:(UIViewController *)controller

    {

        self = [super initWithFrame:frame];

        if (self) {

            self.controller = controller;

        }

        returnself;

    }

0 0
原创粉丝点击