我已经将UITableView(作为KRTableView)进行了子分类,并实现了四种基于touch 的方法(ToucheSBegind、touchesEnded、touchesMoved和touchesCancelled),这样我就可以在UITableView上检测何时正在处理基于touch 的事件.基本上,我需要检测的是UITableView何时向上或向下滚动.
但是,子类化UITableView并创建上述方法只会检测UITableView单元格中何时发生滚动或手指移动,而不是整个UITableView.
一旦我的手指被移动到下一个手机上,touch 事件就什么也做不了.
这就是我对UITableView进行子类化的方式:
#import "KRTableView.h"
@implementation KRTableView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
NSLog(@"touches began...");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
NSLog(@"touchesMoved occured");
}
- (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
NSLog(@"touchesCancelled occured");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
NSLog(@"A tap was detected on KRTableView");
}
@end
如何检测UITableView何时向上或向下滚动?