UITableView Scroll event

前端 未结 3 1441
渐次进展
渐次进展 2020-11-29 09:12

I want to detect if mytable view has been scrolled, I tried all touch events like this one:

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


        
3条回答
  •  迷失自我
    2020-11-29 09:22

    If you implement the UITableViewDelegate protocol, you can also implement one of the UIScrollViewDelegate methods:

    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
    

    or

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    

    For example, if you have a property called tableView:

    // ... setting up the table view here ...
    self.tableView.delegate = self;
    // ...
    
    // Somewhere in your implementation file:
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
    {
        NSLog(@"Will begin dragging");
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        NSLog(@"Did Scroll");
    }
    

    This is because UITableViewDelegate conforms to UIScrollViewDelegate, as can be seen in the documentation or in the header file.

提交回复
热议问题