Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am developing an application in which i have set some images for cells based on some criteria.

After selecting a custom cell i am changing it's image but when i try to select another custom cell.

the image for the previous custom cell remain selected and also the newly selected one.

What i want is that the image of previously selected custom cell should be set to default image which i have given initially.

Kindly help m with this.

Thanks,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
135 views
Welcome To Ask or Share your Answers For Others

1 Answer

Put your criteria in the cellForRowAtIndexPath: method and everytime you update your selected cell probably in didSelectRowAtIndexPath: make a [self.tableView reloadData] that makes the tableView to reload the data and call it's delegate methods again. Hope that helps.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if(requirementMet){ // if your criteria where met
      cell.imageView.image = [UIImage imageNamed:@"specialImage.png"];
    } else{
      cell.imageView.image = [UIImage imageNamed:@"defaultCellImage.png"];
    }

 return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //do your select things here
  [self.tableView reloadData];

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...