我已经将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
Run Code Online (Sandbox Code Playgroud)
如何检测UITableView何时向上或向下滚动?
每当我尝试使用import Metal
我的Swift文件或游乐场时,Xcode都说"没有这样的模块'金属'".这是Beta 1错误吗?