UIView サブクラスのサブレイヤーとして CALayer を追加しようとしていますが、init メソッド内にサブレイヤーEXC_BAD_ACCESS
を追加すると、ビューを別のビューまたはウィンドウに追加したときに取得されます。
初期化方法:
- (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内で呼び出した後に発生します。