I am trying to create a toggle button for each cell in my table. When pressed, it will change the image and when pressed again it will change the image again -- Toggle.
You can do it in a very easy approach. First of all, in your viewDidLoad
set tag for your button. Let's say self.toggleButton.tag = 111
. Now in your button action function, you can toggle the button like :
- (IBAction)toggling:(id)sender{
if(self.toggleButton.tag == 111){
//this is normal state
[self.toggleButton setTitle:@"Less..." forState:UIControlStateNormal];
self.toggleButton.tag = 222;
}else{
//selected state
[self.toggleButton setTitle:@"More..." forState:UIControlStateNormal];
self.toggleButton.tag = 111;
}
}
You can change the image of the button like this [self.toggleButton setImage://some image forState:UIControlStateNormal];
.It's the easiest way I think. Hope it will help.