1

I added multiple buttons in my UITableViewCell wrapped with a toolbar, but all of them are not clickable, once I drag a button to the outside of the table view it's clickable already.

Here is the screenshot of my sample app and scene:

enter image description here

Button 1 is not clickable but button 2 is clickable, User Interaction Enabled has been ticked.

8
  • Plz provide your cellForRowAtIndexPath code... Aug 15, 2014 at 6:50
  • @RamaniAshish but even I tried to create a new Table View Controller with just a button inside, and the cellForRowAtIndexPath just return UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];, the button inside is not clickable as well.
    – Ping
    Aug 15, 2014 at 6:57
  • where is the IBAction of that button...? Aug 15, 2014 at 7:00
  • I recommend you to create custom UITableViewCell and also dont forget to action of button as Ramani said. Aug 15, 2014 at 7:09
  • @RamaniAshish I did tried to create IBAction with just NSLog, but nothing come out as well, if place the button to the outside of table view then it is working already.
    – Ping
    Aug 15, 2014 at 7:20

3 Answers 3

1

Okay found the issue already, was a mistake by my own, it's because I set the tableViewCell "User Interaction Enabled" to NO, cause I want to disable the Table View default row selection.

So I need to set each layers of view "User Interaction Enabled" to YES, then the button is now clickable, thanks for all the replies!

0

Create you button in viewForHeaderInSection, like this..

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
    [sectionView addSubview:btn];

    //add other subviews to section viewww..

    //return
    return sectionView;
}

- (void) btnClicked
{
    //do your thing here..
}
0
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

cell.button.tag = indexPath.row
cell.button.addTarget(self, action: "btnClicked:", forControlEvents: .TouchUpInside)

}
1
  • keep on adding target , this will make your btnClicked call multiple times. May 13, 2020 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.