2013-12-13 39 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"]; 

這種方法一旦呼籲它會顯示出來,不是一次將所有單元的每一個細胞。