我已经将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何时向上或向下滚动?

推荐答案

您不需要拦截事件方法.判断文档中的UIScrollViewDelegate协议,并根据您的情况实施-scrollViewDidScroll:-scrollViewWillBeginDragging:方法.

Objective-c相关问答推荐

如何判断 iPhone 现在在哪个位置(横向或纵向)?

在 iOS 7 上,如果最终包含在选项卡栏控制器中,则使用工具栏推送控制器会留下不可用空间的间隙

多个 WKWebView 之间的 Cookie 共享

如何在 Cocoa 中创建字符串的 MD5 哈希?

NSLocale 和国家名称

iOS 编译错误:CDVCommandDelegateImpl没有可见的@interface 声明 Select 器执行:

在 Xcode 5 中运行代码覆盖时出现数十个profiling:invalid arc tag

如何判断字符串是否仅包含目标C中的字母数字字符?

从 UIPageViewController 中移除视图控制器

UITabBar 未在 ios 7 中显示所选项目图像

如何将小时数添加到 NSDate?

如何将 NSOperationQueue 与 NSURLSession 一起使用?

无法将 searchBar 设置为 firstResponder

NSHTTPCookieStorage 状态未在应用退出时保存.那里有任何明确的知识/文档吗?

UICollectionView 自动调整高度

如何在 Objective-C 中添加具有自己的 UIViewController 的子视图?

笔尖中的原型单元而不是故事板

当 UIView 框架更改时,视图内的 AVPlayer 层不会调整大小

performFetchWithCompletionHandler 永远不会被解雇

如何获得设备的比例因子?