Reputation: 15
I have defined two different UIButton
's in my custom UITableViewCell
. This custom UITableViewCell
is used in a UITableView
inside a UIViewController
. Now i would like to change the UIButton
's image on click. I tried it with protocoll and delegate but it doesn't work. Any idea how i can do this?
Upvotes: 0
Views: 285
Reputation: 661
In your cellforowatindexpath method
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier;
CellIdentifier = @"Cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
UIButton *btn = (UIButton *)[cell viewWithTag: 1]; // or however you are initializing the button
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)btnClicked:(id)sender
{
UIButtin *btn = (UIButton *)sender;
[btn setImage:[UIImage imageNamed:@"click.png"] forState:UIControlStateNormal];
}
Upvotes: 1
Reputation: 75
When you click on your button reload that particular cell and where you make a custom cell define delegate and change backgound Image in delegate section.
May this help you.
Upvotes: 0