2013-12-13 2 views
1
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    static NSDateFormatter *formatter = nil; 
    if (formatter == nil) { 
     formatter = [[NSDateFormatter alloc] init]; 
     [formatter setDateStyle:NSDateFormatterMediumStyle]; 
    } 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    MovieSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row]; 
    [[cell textLabel] setText:sightingAtIndex.titulo]; 
    [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%lu",(unsigned long)sightingAtIndex.anyo]]; 

    [[cell imageView] setImage:[UIImage imageNamed:@"Batman.jpg"] ]; 
    [[cell imageView] setImage:[UIImage imageNamed:@"300.jpg"]]; 


    //cell.imageView.image = [UIImage imageNamed:@"Batman.jpg"]; 
    //cell.imageView.image = [UIImage imageNamed:@"300.jpg"]; 

    //[[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]]; 
    return cell; 
} 

Я хотел бы добавить первое изображение в первую ячейкуцель C ImageView с индексом с TableCell

cell.imageView.image = [UIImage imageNamed:@"Batman.jpg"]; 

Я хотел бы добавить второе изображение на вторую ячейку

cell.imageView.image = [UIImage imageNamed:@"300.jpg"]; 

Я должен делать с atIndex?

ответ

1

Просто проверьте индекс знать ячейку, в которой вы находитесь:

if (indexPath.row == 0) 
    [[cell imageView] setImage:[UIImage imageNamed:@"Batman.jpg"] ]; 
else if (indexPath.row == 1) 
    cell.imageView.image = [UIImage imageNamed:@"300.jpg"]; 

Этот метод вызывается один раз для каждой ячейки он будет отображаться, а не один раз для всех клеток.

Смежные вопросы