在我的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;
}
任何帮助,将不胜感激。
干杯,
克里斯
首先是请使用[tempAnnotationObj.type isEqualToString:@”三“]而不是==,这是比较NSStrings的一种错误方法。那么你可以检查你的if/elseif情况中哪一个条件被选中。 – samfisher
还有一个额外的大括号'}'。示例代码中缺少几行代码? – samfisher
是的,我没有发布一切。只是相关的位 – ChrisM