【发布时间】:2010-12-07 22:54:28
【问题描述】:
我将 UITableView(作为 KRTableView)子类化并实现了四个基于触摸的方法(touchesBegan、touchesEnded、touchesMoved 和 touchesCancelled),以便我可以检测何时在 UITableView 上处理基于触摸的事件。基本上我需要检测的是 UITableView 何时向上或向下滚动。
但是,子类化 UITableView 并创建上述方法仅检测 UITableViewCell 内发生滚动或手指移动的时间,而不是整个 UITableView。
只要我的手指移到下一个单元格上,触摸事件就不会做任何事情。
这就是我继承 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 何时向上或向下滚动?
【问题讨论】:
标签: objective-c iphone cocoa-touch uitableview