我試圖添加一個CALayer作爲UIView子類中的子層,但是當我在init方法中添加子層時,我將EXC_BAD_ACCESS
添加到另一個視圖或窗口中。在UIView中添加一個CALayer子圖層初始化
Init方法:
- (id)initWithTitle:(NSString *)title message:(NSString *)message
{
if ((self = [super init]))
{
self.title = title;
self.message = message;
self.alertLayer = [[CALayer alloc] init];
self.layer.cornerRadius = kCORNER_RADIUS;
self.layer.shadowRadius = 3.0;
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(15, 20);
self.layer.shadowOpacity = 1.0;
self.alertLayer.delegate = self;
self.alertLayer.masksToBounds = YES;
self.alertLayer.cornerRadius = kCORNER_RADIUS;
[self.layer addSublayer:self.alertLayer]; // This line of code seems to cause EXC_BAD_ACCESS
}
return self;
}
EXC_BAD_ACCESS
正在呼叫[self.view addSubview:alertView]
視圖控制器或一個UIWindow內部之後引起的。
你爲alertLayer屬性使用了什麼內存管理語義? – jlehr