tableview图像没有刷新

时间:2011-09-27 11:12:41

标签: objective-c uitableview uiimage

在我的cellForRowAtIndexPath委托中我试图将不同的图像加载到自定义单元格中,具体取决于将哪个数组(detailViewListLoadMore)加载到表中。该数组包含注释对象。

然而,图像似乎没有刷新,它们似乎与最后一个数组相同,除非我向下滚动然后它们是正确的,就像它们从最后一个数组预加载一样。

这是我的方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

//set up custom table cell
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";

//reuse the custom cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier]; 

//setup custom cell
if (cell == nil) {

    //load custom cell from nib
    NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"CustomDetailViewCell"
                                                      owner:self
                                                    options:nil];

    if ([nibArray count] > 0)
        cell = self.detailCell;
    else
        NSLog(@"failed to load CustomDetailViewCell nib file");

} 

//configure the cell row
NSUInteger row = [indexPath row];

//create temp cell lable strings
NSString *headingString, *detailString, *subDetailString, *imageString;
UIImage *cellDistanceImage;

//create temp annotation object
Annotation *tempAnnotationObj = [detailViewListLoadMore objectAtIndex:row];            

if (tempAnnotationObj.type == @"one")
    cellDistanceImage = [UIImage imageNamed:@"AnnotationOne.png"];
else if (tempAnnotationObj.type == @"two")
    cellDistanceImage = [UIImage imageNamed:@"AnnotationTwo.png"];
else if (tempAnnotationObj.type == @"three")
    cellDistanceImage = [UIImage imageNamed:@"AnnotationThree.png"];

}

//set table cell strings
headingString = tempAnnotationObj.streetName;
detailString = [NSString stringWithFormat:@"No of Bays: %@",tempAnnotationObj.bays];
        subDetailString = [NSString stringWithFormat:@"%@m",tempAnnotationObj.distance];           

//update heading label
UILabel *headingLabel = (UILabel *)[cell viewWithTag:1];
headingLabel.text = headingString;

//update detail label
UILabel *detailLabel = (UILabel *)[cell viewWithTag:2];
detailLabel.text = detailString;

//update sub detail label
UILabel *subDetailLabel = (UILabel *)[cell viewWithTag:3];
subDetailLabel.text = subDetailString;    

//set appropriate distance image
[self.detailCellImage setImage:cellDistanceImage];

return cell;
}

任何帮助都将不胜感激。

干杯,

克里斯

3 个答案:

答案 0 :(得分:0)

您是否尝试将[tableView reloadData];放入更改tableView数据源的方法中?

答案 1 :(得分:0)

为什么要设置

//set appropriate distance image
[self.detailCellImage setImage:cellDistanceImage];
如果要在单元格上设置图像,请使用self?我认为应该是

  

cell.detailCellImage

答案 2 :(得分:0)

似乎用它来解决....

UIImageView *anImageView = (UIImageView *)[cell viewWithTag:4];
[anImageView setImage:cellDistanceImage];