How to detect tap on Uitableview cell with uiview and uibutton?

后端 未结 3 2017
南方客
南方客 2021-01-25 22:12

I have created a table view and i am adding my custom uiview into the cell\'s content view. The uiview has a uibutton. However i can add the uibutton into the content view when

3条回答
  •  自闭症患者
    2021-01-25 22:17

    Are you sure two different events are being triggered by the same tap? My understanding is that UIKit generates only one UIEvent and sends it to the top-most view in the hierarchy that responds to that type of gesture. In this case, if the button is higher in the view hierarchy, as it probably is, it should be receiving the event message. But, I may be wrong.

    One solution to definitely avoid the possibility of two events being triggered, though possibly not the ideal, would be to deactivate row selection for the tableView, as follows:

            self.tableView.allowsSelection = NO;
    

    Then, add a view covering the remainder of the tableCell & add a gesture recognizer to that view. Since they don't cover the same area, there is no chance of conflicting events. Of course, to know what row was tapped, you'd have to add an instance variable for both the button and the new view to hold the indexPath. You would set the index path when you set up the tableCell in tableView:cellForRowAtIndexPath:

    Hope this is helpful or gives you some new ideas.

提交回复
热议问题