除非下面的委托分配被注释掉,否则我的 UIButton 的目标操作不会被调用,但是我会丢失我的自定义绘图。我错过了什么?
- (void)createLayerForPaletteAtIndex:(int)paletteIndex onButton:(UIButton *)button
{
self.colorPaletteLayer = button.layer;
self.colorPaletteLayer.delegate = self; // Must implement drawLayer:inContext
NSString *stringForIndex = [NSString stringWithFormat:@"%d",paletteIndex];
self.colorPaletteLayer.name = stringForIndex;
button.clearsContextBeforeDrawing = YES;
button.layer.opaque = YES;
[self.colorPaletteLayer setNeedsDisplay]; // Calls drawLayer:inContext
}