dont know whats wrong with my table view, I have a dictionary(this dictionary is created by a sqlite operation) and I am trying to create cells like this
- (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;
}
a开发者_C百科ll the items are displayed correctly but when I scroll the table view up the application crashes can you help me in this?
You are first allocating a new NSMutableDictionary and store it in tempDictionary
. However, in the very next line, you overwrite that variable with a pointer to a new object (tempDictionary=[offendersNamesList objectForKey:[NSString stringWithFormat:@"key%d", indexPath.row+1]];
). So you've got a memory leak here, the [[NSMutableDictionary alloc] init]
is unnecessary, remove it.
Now, due to the naming conventions, the object that you've got from the offendersNamesList
is autoreleased, yet you later call [tempDictionary release];
and thus over-release it. Remove that as well.
精彩评论