UIButton does not receive touch events inside custom UITableViewCell

I developed a custom UItableView cell in IB. This cell has a UIButton with an associated action. This button does not receive touch events, but the cell itself receives events when called.

What can I do wrong here.

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

When you click on the button, Tableviewcell receives events. What could be wrong?

EDIT:

I just checked that UIButton also receives touch events, but also UITableViewCell. And at the end of this action, the action associated with UIButton is not called.

+3
source share
4 answers

. , , , , " ", .

+1

, ,

, .

0

customtablecell.h
, . UIViewController *parentViewController;

customtablecell.m

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

customtablecell xib -(IBAction)myButtonAction:(id)sender

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

, IBAction, UIControlEventTouchUpInside, . .

0

Source: https://habr.com/ru/post/1782021/


All Articles