Challenge:More Data without UITableViewCell subclas,with tag


#1

UTube tutorial “Creating custom a UITableViewCell with Interface Builder” by JulioEBarros said there are 3 ways to customize the table cell.

This is a simpler way.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     
     static NSString *CellIdentifier = @"ItemCell";
     static NSInteger titleTag = 1;
     static NSInteger authorTag = 2;
     static NSInteger categoryTag = 3;
     
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     if (cell == nil) {
//         cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     
         CGRect frame;
         frame.origin.x = 2;
         frame.origin.y = 2;
         frame.size.height = 17;
         frame.size.width = 375;
     
         UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
         titleLabel.tag = titleTag;
         [cell.contentView addSubview:titleLabel];
         [titleLabel release];
     
         frame.origin.x += 4 + 375 + 4;
                        
         UILabel *authorLabel = [[UILabel alloc] initWithFrame:frame];
         authorLabel.tag = authorTag;
         [cell.contentView addSubview:authorLabel];
         [authorLabel release];
     
         frame.origin.x = 4;
         frame.origin.y = 23;
         UILabel *categoryLabel = [[UILabel alloc] initWithFrame:frame];
         categoryLabel.tag = categoryTag;
         [cell.contentView addSubview:categoryLabel];
         [categoryLabel release];
         
     }  
     
     UILabel *titleLabel = (UILabel *)[cell.contentView viewWithTag];
     UILabel *authorLabel = (UILabel *)[cell.contentView viewWithTag:authorTag];
     UILabel *categoryLabel = (UILabel *)[cell.contentView viewWithTag:categoryTag];
     
     RSSItem *item = [[channel items] objectAtIndex:[indexPath row]];
     
     titleLabel.text = [item title];
     authorLabel.text = [item author];
     categoryLabel.text = [item category];
     
 
     return  cell;
 
}