2012-09-02 45 views
2

我是继承UIView并使用它的实例来设置我的UITableViewCell backgroundView和selectedBackedView属性。我在UIView子类的drawRect方法中收到EXC_BAD_ACCESS错误。CGContextRef - EXC_BAD_ACCESS错误

if(nil == cell){ 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
           reuseIdentifier:CellIdentifier]; 
    cell.backgroundView = [[CCViewBackground alloc]init]; 
    cell.selectedBackgroundView = [[CCViewBackground alloc]init]; 

    } 

UIView子类CCBackgroundView -drawRect:

- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGColorRef redColor = 
    [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0].CGColor; 

    CGContextSetFillColorWithColor(context, redColor); //Receiving EXC_BAD_ACCESS here 
    CGContextFillRect(context, self.bounds); 

} 
+0

你能为你的应用启用NSZombie并分享接收的原因EXC_BAD_ACCESS –

+0

这是现在NSZombie启用的错误信息 - *** - [Not A Type retain]:发送到释放实例的消息0x109b50 – Michael

回答

4

我假设你正在使用ARC。如果是这样,那么CGColorRef的发布时间早于您的预期,您将遇到一个众所周知的问题。 This article详细解释了问题并提供了几种解决方案。

+0

是的,我是使用弧。感谢您的文章,它修复了问题 – Michael

+0

赞美互联网!这解决了它,谢谢你的文章! –

+0

有人可以再次分享文章的链接...现在是断开的链接。 – Queen