2011-05-03 29 views
0

不知道什麼是錯我的表視圖,我有一本字典(該字典由sqlite的操作創建),我試圖創建細胞這樣iphone:UITableView的崩潰應用

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

static NSString *MyIdentifier = @"MyIdentifier"; 
MyIdentifier = @"tblCellView"; 

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if(cell == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
    cell = aCustomCell; 
    aCustomCell=nil; 
} 

NSMutableDictionary *tempDictionary=[[NSMutableDictionary alloc] init]; 

tempDictionary=[offendersNamesList objectForKey:[NSString stringWithFormat:@"key%d", indexPath.row+1]]; 

[[cell offendersImageView] setImage:[UIImage imageNamed:@"contact.png"]]; 
[cell.offendersNameLbl setText:[tempDictionary objectForKey:@"name"]]; 
[cell.offendersViolation setText:[tempDictionary objectForKey:@"offence"]]; 
[tempDictionary release]; 

//[cell setLabelText:[arryData objectAtIndex:indexPath.row]]; 
return cell; 

}

所有的項目都顯示正確,但當我滾動表視圖時,應用程序崩潰可以幫助我嗎?

回答

2

您首先分配一個新的NSMutableDictionary並將其存儲在tempDictionary中。但是,在下一行中,用一個指向新對象的指針覆蓋該變量(tempDictionary=[offendersNamesList objectForKey:[NSString stringWithFormat:@"key%d", indexPath.row+1]];)。所以你在這裏有內存泄漏,[[NSMutableDictionary alloc] init]是不必要的,刪除它。

現在,由於命名約定,您從offendersNamesList獲得的對象是自動發佈的,但您稍後調用[tempDictionary release];並因此過度釋放它。除去這一點。