didSelectRowAtIndexPath: not being called

前端 未结 14 2180
轻奢々
轻奢々 2020-11-29 18:57

I have a UITableView as a subview of my UIScrollVIew, which is the main view controlled by my MainViewController.

In MainView

相关标签:
14条回答
  • 2020-11-29 19:23

    Sorry, haven't got enough points to add comments - Garret's answer is great but I would add:

    You can still have your gesture recognizer but you will need to set 'Cancels touches in view' to NO - then the gestures will be handed on to the view and your UITableView will work fine.

    After trying many, many approaches this seems to be the correct way of doing things: a tap gesture recognizer with 'cancel touches in view' is like having an invisible layer on top of everything that grabs all the events and routes them to the view controller (the proxy). The view controller then looks at the gesture to see if it has an action binding (buttons etc.) and will route those and any remaining will just go to the gesture handler. When using a UITableView it is expecting to receive the tap but the view controller snaffles it when you have 'Cancels touches in view'.

    0 讨论(0)
  • 2020-11-29 19:24

    Cancel the other views touches except required one.

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture shouldReceiveTouch:(UITouch *)touch {
        if (touch.view == your view) {
            return YES;
        }
        return NO;
    }
    
    0 讨论(0)
提交回复
热议问题