Q:

How to detect multiple buttons in tableview cell

How to  detect multiple buttons in tableview cell and my doubt is with example i have 3 buttons in cell if i tap on one button that button will change colour and and if i click  indexpath.row=1 cell  button that button will color also need to change help me 

A:

I did like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:MyIdentifier];
    }

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(10.0, 0.0, self.tableView.frame.size.width/4, 40.0);
    button.tag = 100 + indexPath.row*total_buttons_in_a_row;
    [button setTitle:[NSString stringWithFormat:@"%ld",(long)button.tag] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:button];

    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button2.frame = CGRectMake(10.0+self.tableView.frame.size.width/4+10.0, 0.0, self.tableView.frame.size.width/4, 40.0);
    button2.tag = 100 + indexPath.row*total_buttons_in_a_row + 1;
    [button2 setTitle:[NSString stringWithFormat:@"%ld",(long)button2.tag] forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:button2];

    UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button3.frame = CGRectMake(10.0+self.tableView.frame.size.width/4*2+10.0, 0.0, self.tableView.frame.size.width/4, 40.0);
    button3.tag = 100 + indexPath.row*total_buttons_in_a_row + 2;
    [button3 setTitle:[NSString stringWithFormat:@"%ld",(long)button3.tag] forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:button3];

    return cell;
}

-(void)btnClicked:(UIButton *)sender{
    id selectedButton = [self.view viewWithTag:sender.tag];
    if ([selectedButton backgroundColor] == [UIColor redColor]) {
        [selectedButton setBackgroundColor:[UIColor clearColor]];

    }else{
        [selectedButton setBackgroundColor:[UIColor redColor]];
    }
}

total_buttons_in_a_row is an Int. In your case define it in viewDidLoad total_buttons_in_a_row=3
P.S - set the Buttons CGRectMake according to your need.

