开发者

tableview image not getting refreshed

in my cellForRowAtIndexPath delegate i am trying to load different images into a custom cell depending on which array (detailViewListLoadMore) is being loaded into the table. The array contains annotation objects.

however the images dont seem to refresh, they seem to be the same as the last array unless i scroll down and then they are correct, its like they are being pre loaded from the last array.

here is my method:

- (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;
}

Any help would be appreciated.

Cheers,

Chris


Have you tried putting [tableView reloadData]; into the method that changes tableView's data source?


why you have set

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

with self if you want to set image on cell? i think it should be

cell.detailCellImage


seemed to work it out using this....

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜