UITableView Scroll事件 [英] UITableView Scroll event
问题描述
我想检测是否滚动了mytable视图,我尝试了所有触摸事件,如下所示:
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
{
[super touchesBegan:touches withEvent:event];
//my code
}
但似乎所有触摸事件都没有不响应滚动,但只有当单元格被触摸,移动等时它们才会响应
but it seems that all touch events don't response to scroll but they response only when cells are touched, moved,...etc
有没有办法检测UITableView的滚动事件?
Is there a way to detect scroll event of UITableView ?
推荐答案
如果你实现 UITableViewDelegate
协议,你也可以实现一个 UIScrollViewDelegate
一>方法:
If you implement the UITableViewDelegate
protocol, you can also implement one of the UIScrollViewDelegate
methods:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
或
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
例如,如果你有一个名为的属性tableView
:
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");
}
这是因为 UITableViewDelegate
符合 UIScrollViewDelegate
,如文档或头文件中所示。
This is because UITableViewDelegate
conforms to UIScrollViewDelegate
, as can be seen in the documentation or in the header file.
这篇关于UITableView Scroll事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!