samouray
samouray

Reputation: 578

Error while changing image of UIButton inside Tableview Cell

I have a UIButton inside a TableView Cell:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {

  UIButton *ImageViewFavorited = (UIButton *)[cell viewWithTag:7];

        [ImageViewFavorited addTarget:self action:@selector(BtnClicked:) forControlEvents:UIControlEventTouchUpInside];

}

I want to change the background image for this button on click event so I have an Action tied to this button :

- (IBAction)BtnClicked:(id)sender {
    NSLog(@"I enter in  BtnClicked");
    UIImage *ImageNNotFavorited = [UIImage imageNamed:@"NotFavorited"];

    [sender setImage:ImageNNotFavorited];
}

After running this code I have the following Error:

-[UIButton setImage:]: unrecognized selector sent to instance 0x7fd19c83ea00

I don't know how to fix this, do you have an idea ?

Upvotes: 1

Views: 42

Answers (1)

Michael Hulet
Michael Hulet

Reputation: 3499

To set the image on a UIButton, you also need to specify what control state you want the image to be shown for. For example:

[sender setImage:ImageNNotFavorited forState:UIControlStateNormal];

Upvotes: 4

Related Questions