I am trying to add CALayer as a sublayer in a subclass of UIView, but when I add a sublayer inside the init method, I get EXC_BAD_ACCESSwhen I add a view to another view or window.
Init Method:
- (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];
}
return self;
}
EXC_BAD_ACCESScalled after a call [self.view addSubview:alertView]inside the view controller or UIWindow.
source
share