tags:

views:

28

answers:

1

Hi Guys,

This problem drove me crazy for couple of days. I have a customized uitableview cell with 5 buttons on it. And each button has three images. 1 the original one. 2 When user tapped on it,the image will be changed to "Selected.png". 3 When user double tapped on it, image will be changed to the 3rd one.

When user tapped on a button, i will call setBackgroundImage:forState to that button. However, The background image of another buttons on another uitableviewcells also changed. I know it is because of reusing the tableviewcell, but how could i fix this problem? I searched a lot but still no luck.

Any one could help me, i really appreciate.

A: 

You have to give tab index to each button and on click using that tag index you can solve this

Before tap count you need to check tab index as below :

-(IBAction)btnClicked:(id)sender
 { 
    MyCellButton cellButton = (MyCellButton)sender;
    cellButton.tapCount++;
    if([sender tag] == 1)
    {
          if (cellButton.tapCount == 1) { 
                   [cellButton setBackgroundImage:[UIImage imageNamed:@"Selected.png"] forState:UIControlStateNormal withTag:buttonTag]; 
          } 
          else if(cellButton.tapCount == 2)
          { 
                 [cellButton setBackgroundImage:[UIImage imageNamed:@"Guessed.png"] forState:UIControlStateNormal]; 
          }
    } 
 } 
Reena
Thanks for your answer. However, when i created those buttons, i did set their tag properties. This is code snippet:-(IBAction)btnClicked:(id)sender{ MyCellButton *cellButton = (MyCellButton*)sender; cellButton.tapCount++; if (cellButton.tapCount == 1) { [cellButton setBackgroundImage:[UIImage imageNamed:@"Selected.png"] forState:UIControlStateNormal withTag:buttonTag]; } else if(cellButton.tapCount == 2){ [cellButton setBackgroundImage:[UIImage imageNamed:@"Guessed.png"] forState:UIControlStateNormal]; }}
Jackie
Hi Reena, I really appreciate your kind help. I tried what you said but still not working. This is really a problem and i tested with apple's sample "TouchCell", it also happened. I guess no one has done this before. My email address is: [email protected]. If you don't mind, please send me your email address, i can send you my project. Please excuse my confused description, but it is sort of different from what you think. Thank you so much for your kind help again~~
Jackie