Hi everyone, i've another problem with the UITableView, app crashes after reloading tableView after loading data from internet, the crash happens in marked place in cellForRowAtIndexPath methood. I thinnk i still don't fully understand what actually mean recycling cells. Thanks for any help
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UILabel *venueName;
UIImageView *logo;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSLog(@">>> GIT 1<<<");
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
venueName = [[UILabel alloc] initWithFrame:CGRectZero];
[venueName setLineBreakMode:UILineBreakModeWordWrap];
[venueName setMinimumFontSize:FONT_SIZE];
[venueName setNumberOfLines:0];
[venueName setFont:[UIFont systemFontOfSize:FONT_SIZE]];
[venueName setTag:1];
venueName.backgroundColor = [UIColor clearColor];
[[cell contentView] addSubview:venueName];
logo = [[UIImageView alloc] initWithFrame:CGRectZero];
[logo setTag:10];
[[cell contentView] addSubview:logo];
cell.backgroundView = [[[UIImageView alloc] init] autorelease];//new
}
NSMutableDictionary *oneVenue ;
if ([self.venueList count] > 0) {
oneVenue = [self.venueList objectAtIndex:indexPath.row];
if (!venueName) {
venueName = (UILabel*)[cell viewWithTag:1];
}
[venueName setText:[oneVenue objectForKey:@"Name"]]; // <===CRASH!!!
[venueName setFrame:CGRectMake(CELL_CONTENT_MARGIN,CELL_VENUE_LEVEL ,80 , 30)];
[logo setImage:[UIImage imageNamed:@"event.png"]];
[logo setFrame:CGRectMake(10, 5, 76, 60)];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImage *rowBackground;
rowBackground = [UIImage imageNamed:@"evbgd_yell.png"];
((UIImageView *)cell.backgroundView).image = rowBackground;
}
return cell;
}