2011-05-03 2 views
0

, 나는 사전 (이 사전이 SQLite는 작업에 의해 생성되는)가 무슨 잘못 내 테이블보기 몰라요 응용 프로그램을 충돌하고 나는이아이폰 : jQuery과는

- (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];을 호출하여 과도하게 릴리스합니다. 그것을 제거하십시오.