2012-09-02 42 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