Why does my UITableView not respond to touchesBegan?

后端 未结 3 919
-上瘾入骨i
-上瘾入骨i 2021-01-21 18:22

I am using this method

- (void)tableView:(UITableView *)tableView touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTou         


        
3条回答
  •  猫巷女王i
    2021-01-21 18:54

    I found the simplest way to do this is to add a gesture recognizer to the UITableViewController's view.

    I put this code in the UITableViewController's viewDidLoad:

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [self.view addGestureRecognizer:tap];
    

    And implemented the event handler:

    - (void)handleTap:(UITapGestureRecognizer *)recognizer
    {
        // your code goes here...
    }
    

    EDIT: You could also add the gesture recognizer to the tableview, just change [self.view addGestureRecognizer:tap]; to [self.tableView addGestureRecognizer:tap];

提交回复
热议问题