2011-09-27 94 views
0

在我的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; 
} 

任何帮助,将不胜感激。

干杯,

克里斯

+0

首先是请使用[tempAnnotationObj.type isEqualToString:@”三“]而不是==,这是比较NSStrings的一种错误方法。那么你可以检查你的if/elseif情况中哪一个条件被选中。 – samfisher

+0

还有一个额外的大括号'}'。示例代码中缺少几行代码? – samfisher

+0

是的,我没有发布一切。只是相关的位 – ChrisM

回答

0

似乎解决它使用这个....

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

你有没有试图把[tableView reloadData];到改变的tableView的数据源的方法?

+0

是的,我试过了,仍然没有工作 – ChrisM

0

为什么你已经设置

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

与自我,如果你想设置单元格的形象?我觉得应该是

cell.detailCellImage

+0

,因为对于细胞图像我创建了一个UIImageView并将其链接到IB。如果我将其更改为单元格,我会在“UITableViewCell *”类型的对象中找到错误“属性'detailCellImage'” – ChrisM

+0

哦..因此,您正在类中保留一个imageview,并且所有单元格上都显示单个图像视图? – samfisher

+0

我不知道为什么我这样设置它,但我不希望它保留在我的课堂。我改变了它... UIImageView * anImageView =(UIImageView *)[cell viewWithTag:4]; [anImageView setImage:cellDistanceImage ] ;.似乎工作正常,不知道为什么我没有这样做之前这样做 – ChrisM