Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone development: changing the button image on tableviewcell
    text
    copied!<p>In my app I am facing with a really weird problem. I am trying to solve it for hours but could not find what is the problem so far. </p> <p>Well, I have a tableview with custom cells. and each cell I have a button. It is is like an empty box. When the button pressed, I want to change the related cell image of that button. Actually I successfully do that but somehow, some other cell's button images are also changing and I could not figure out why. Here is my code:</p> <pre><code> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"cell"; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { //create new cell cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } [cell.tickButton setTag:indexPath.row]; [cell.tickButton addTarget:self action:@selector(buttonWasPressed:)forControlEvents:UIControlEventTouchUpInside]; //cell has 2 label so I filled them with the contents of my object array that part is working with no problem cell.leftLabel.text = [NSString stringWithFormat:@"%@", [[contacts objectAtIndex:indexPath.row]name]]; cell.rightLabel.text = [NSString stringWithFormat:@"%@", [[contacts objectAtIndex:indexPath.row]email]]; return cell; } </code></pre> <p>in my buttonWasPressed method I simply do:</p> <pre><code>-(IBAction)buttonWasPressed:(id)sender { UIButton *button = (UIButton *)sender; [button setImage:[UIImage imageNamed:@"ticck.jpeg"] forState:UIControlStateNormal]; } </code></pre> <p>As I said before it works but also changes some other buttons images and also when I scroll down and get back to the initial position I see that some button images are changed.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload