UIButton inside UITableViewCell steals touch from UITableView

前端 未结 4 716
终归单人心
终归单人心 2021-02-14 21:14

I have a problem similar to this one but answer provided there doesn\'t help much. I have UITableView with some custom UITableViewCells, those cells ha

4条回答
  •  终归单人心
    2021-02-14 21:56

    You can change the behaviour by overriding touchesShouldCancelInContentView: in the UITableView. For this to work you'll need to replace the table view with this subclass, either in loadView or in your xib file.

    @interface AutoCancelTableView: UITableView
    @end
    
    @implementation AutoCancelTableView
    
    //
    // Overriding touchesShouldCanceInContentView changes the behaviour
    // of button selection in a table view to act like cell selection -
    // dragging while clicking a button will cancel the click and allow
    // the scrolling to occur
    //
    - (BOOL)touchesShouldCancelInContentView:(UIView *)view {
        return YES;
    }
    
    @end
    

提交回复
热议问题