Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

iphone - How to set image of custom cell after selecting another cell?

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

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

1 Reply

0 votes
by (71.8m points)

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];

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...