在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;
}
return self;
}