2011-12-13 16 views
0

在我的索引方法行我使用的代碼 休耕線當我的應用程序的tableview細胞應用分析我得到了休耕泄漏在初始化期間存儲到單元格的值從未在cellForRowAtIndex方法中讀取?

代碼:

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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    //if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    //} 

    // Configure the cell... 
} 

我得到的錯誤是這樣 價值的動初始化期間存儲於電池沒讀過

請幫助任何一個

在此先感謝

回答

1

您初始化稱爲在此行中「細胞」中的局部變量:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

然後立即覆蓋在下一行值:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

分析儀正在呼籲您注意這一點。

在這種特殊情況下,這實際上不會導致泄漏。但是這意味着你沒有重複使用單元格,所以這會影響你的表格視圖的性能。

+0

感謝您的回覆我試過這一個評論第一行它沒有給出錯誤。 –

+0

你爲什麼試圖避免回收細胞? –

+0

// if(cell == nil)are you told abt this line of code我有大量的行,如果我使用這個數據將被混合我的意思是覆蓋 –

2

您初始化在此行被稱爲「細胞」中的局部變量:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

然後立即覆蓋在下一行值:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

分析儀正在召喚你的注意這個。

在這種特殊情況下,這實際上不會導致泄漏。但是這意味着你沒有重複使用單元格,所以這會影響你的表格視圖的性能。

如果你想刪除這個警告&不用擔心UITableView的性能,那麼你需要在上面的代碼中添加2行代碼。請按照下面的代碼。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if(cell!=nil) 
    cell=nil; 
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

上面的代碼將很好地工作&刪除警告。

相關問題