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.

modusCell
  • 13,151
  • 9
  • 53
  • 80
Ping
  • 339
  • 7
  • 18
  • Plz provide your cellForRowAtIndexPath code... – Ashish Ramani Aug 15 '14 at 06: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 '14 at 06:57
  • where is the IBAction of that button...? – Ashish Ramani Aug 15 '14 at 07:00
  • I recommend you to create custom UITableViewCell and also dont forget to action of button as Ramani said. – Yucel Bayram Aug 15 '14 at 07: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 '14 at 07:20
  • @yucel-bayram I'm still new to iOS actually and I am using XIB to create my interface entirely, just not sure why the button cannot be click. – Ping Aug 15 '14 at 07:22
  • @RamaniAshish here is my screenshot in color blend mode: [link](http://i.imgur.com/haHzwyq.png), it's actually the same issue with this I guess: [link](http://stackoverflow.com/questions/20798475/button-inside-table-cell-not-clickable) – Ping Aug 15 '14 at 07:44
  • You better check this out if UIButton exist in your tableViewCell in runtime , this link can help you http://stackoverflow.com/questions/14751949/check-if-uibutton-already-exists-on-uitableviewcell – Yucel Bayram Aug 15 '14 at 10:22

3 Answers3

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!

Ping
  • 339
  • 7
  • 18
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..
}
Ty Lertwichaiworawit
  • 2,950
  • 2
  • 23
  • 42
0
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

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

}
Anand
  • 71
  • 1
  • 11