3
votes

I have designed a custom UItableView Cell in IB. This cell has a UIButton with an associated action. This button is not getting touch events, however the cell itself gets the events when called.

What could I be doing wrong here.

+--------------------------------+
|                     +----------+
|  Cell               | Button   |
|                     +----------+
+--------------------------------+

When I tap on the Button tableviewcell gets the events. What could be wrong?

EDIT:

I just checked, that UIButton is also getting touch events, but so is the UITableViewCell. And at then end of it the action associated with UIButton is not getting called.

4

4 Answers

2
votes

I had the same issue. Finally noticed that the button in question had its "User Interaction Enabled" checkbox unchecked in the attributes inspector.

0
votes

This might not be correct, but is work around,

If I create the button dynamically in code, the application works fine.

0
votes

In customtablecell.h
You need to declare a new controller e.g. UIViewController *parentViewController;
Do property and synthesize
write below lines of code in customtablecell.m file

-(IBAction)myButtonAction:(id)sender {
 if (self.parentViewController) { 
        [self.parentViewController performSelector:@selector(myButtonClicked: forCellWithLabel:) withObject:sender withObject:[self.NameOfTrack text]];
    }
}

in customtablecell xib connect this -(IBAction)myButtonAction:(id)sender to button

in tableViewController

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method
cell.parentViewController = self;





- (void)myButtonClicked:(id)sender forCellWithLabel:(NSString *)text {
    UIButton *button = (UIButton  *)sender;
  //Do some thing

}
0
votes

Make sure that you have an IBAction associated with this button for the state UIControlEventTouchUpInside and the user interaction are enabled. The file owner should then receive the touch event.