我使用了一些源代码:
KGModalContainerView *containerView =
self.containerView =
[[KGModalContainerView alloc] initWithFrame:containerViewRect];
它给了我:Assigning retained object to weak property;赋值后对象将被释放
编辑:
@interface KGModal()
@property (strong, nonatomic) UIWindow *window;
@property (weak, nonatomic) KGModalViewController *viewController;
@property (weak, nonatomic) KGModalContainerView *containerView;
@property (weak, nonatomic) UIView *contentView;
@end
KGModalContainerView *containerView =
self.containerView =
[[KGModalContainerView alloc] initWithFrame:containerViewRect];
containerView.modalBackgroundColor = self.modalBackgroundColor;
containerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
containerView.layer.rasterizationScale = [[UIScreen mainScreen] scale];
contentView.frame = (CGRect){padding, padding, contentView.bounds.size};
[containerView addSubview:contentView];
[viewController.view addSubview:containerView];
最佳答案
我想您的 containerView
属性是用 weak
属性声明的。如果您希望某个属性具有 weak
属性,应该有人已经保留了它。这是一个例子:
@property (nonatomic, weak) KGModalContainerView *containerView;
...
-(void)viewDidLoad {
[super viewDidLoad];
KGModalContainerView *myContainerView = [[KGModalContainerView alloc] initWithFrame:containerViewRect]; // This is a strong reference to that view
[self.view addSubview:myContainerView]; //Here self.view retains myContainerView
self.containerView = myContainerView; // Now self.containerView has weak reference to that view, but if your self.view removes this view, self.containerView will automatically go to nil.
// In the end ARC will release myContainerView, but it's retained by self.view and weak referenced by self.containerView
}
关于iphone - 将保留的对象分配给弱属性;对象将在分配后释放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15110017/