检测下表中的触摸的IOS UITableView - 需要子类化吗?

kri*_*ris 1 iphone uitableview touch-event ios

我希望能够检测用户何时点击我的UITableView的最后一行,但不会对滚动表的能力产生负面影响.有没有比继承UITableView更简单的方法(即覆盖表的touchesBegan)?

我想这样做的原因是:当表为空(第一次打开应用程序)或只有几个单元格时,可以点击屏幕上的所有空间来调用Add方法.

我尝试在一个大的tableview页脚中使用一个没有图像(即不可见)的大型自定义UIButton,但按下该按钮会阻止任何滚动,但是一旦已经有一些单元格,你就想滚动.我想我可以在表格中有超过零的项目时从页脚中删除按钮,但是当表格中有几个项目时,这对我没有任何作用.

谢谢你的任何想法!

kri*_*ris 8

在tableView的页脚上设置了一个轻击手势识别器,这对我来说已经成功了.正如所宣传的那样,它会检测到一个点击,但通过其他手势(如滚动)到UITableView就好了.

//In viewDidLoad 
//configure footerView with gesture recognizer
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]
                                            initWithTarget:self action:@selector(handleSingleTapOnFooter:)];
singleTap.numberOfTapsRequired = 1;
[self.footerView addGestureRecognizer:singleTap];
[singleTap release];
self.tableView.tableFooterView = self.footerView;

//Later on, implement the corresponding method
- (IBAction) handleSingleTapOnFooter: (UIGestureRecognizer *) sender {
    NSLog(@"The footer was tapped!");
    // code to add an entry to the table here
}
Run Code Online (Sandbox Code Playgroud)

footerView是我在视图控制器的nib文件中创建的UIView,并附加到视图控制器中的UIView插座.

我想更好的解决方案是在UITableView本身上设置一个轻击手势识别器,其代码用于识别水龙头的位置是否在最后一个小区之后.如果我开始尝试,我会更新.