2013-02-28 27 views
0

我在我的cellForRowAtIndexPath下面的代碼:可以設置對象層導致內存問題?

cell.appImageLogo.layer.cornerRadius = 10.0; 
cell.appImageLogo.layer.masksToBounds = YES; 
cell.appImageLogo.layer.borderColor = [UIColor clearColor].CGColor; 
cell.appImageLogo.layer.borderWidth = 2.0; 

我的問題是:它可以導致內存問題&如果是,如何釋放它所佔用的內存?任何幫助將不勝感激。

+0

應該沒問題。你爲什麼會這樣想?如果您懷疑泄漏,請通過儀器泄漏工具運行您的代碼。 (尤其是非ARC代碼),通過靜態分析器運行。 – Rob 2013-02-28 06:51:51

回答

1

如果你的單元格沒有被重用,並且單元格數量不是很多,或者如果你的單元格被重用,它不會導致內存問題。

,如果你的電池可重複使用,如果cornerRadiusborderColor等屬性是一樣的,你可以在聲明代碼,在小區nil

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 


    static NSString *CellIdentifier = @"YOURSTRING"; 
    YourCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if(cell==nil){ 

     cell = [[YourCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

     cell.appImageLogo.layer.cornerRadius = 10.0; 
     cell.appImageLogo.layer.masksToBounds = YES; 
     cell.appImageLogo.layer.borderColor = [UIColor clearColor].CGColor; 
     cell.appImageLogo.layer.borderWidth = 2.0; 

     } 
     // other different settings for different cells 
     return cell; 

    } 
0

這使得在內存方面沒有區別。該單元無論如何都有一個圖層,並且該圖層上的屬性更改不會影響內存消耗。

順便說一下,你將邊框設置爲一個清晰的顏色?當然,根本不設置它沒有區別?