我已经添加了单击和双击手势识别器到UITableViewCells。但在滚动桌面几次之后,在滑动桌面的滑动手势结束和滚动动画的开始之间会出现更长的暂停。UITableViewCell的性能问题GestureReognizer
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"tableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[cell addGestureRecognizer:singleTap];
UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
[singleTap requireGestureRecognizerToFail:doubleTap];
[cell addGestureRecognizer:doubleTap];
if (tableView == self.searchDisplayController.searchResultsTableView) {
// search results
}
else {
// normal table
}
return cell;
}
SingleTap:和doubleTap:方法
- (void)singleTap:(UITapGestureRecognizer *)tap
{
if (UIGestureRecognizerStateEnded == tap.state) {
UITableViewCell *cell = (UITableViewCell *)tap.view;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// do single tap
}
}
- (void)doubleTap:(UITapGestureRecognizer *)tap
{
if (UIGestureRecognizerStateEnded == tap.state) {
UITableViewCell *cell = (UITableViewCell *)tap.view;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath* indexPath = [tableView indexPathForCell:cell];
[tableView deselectRowAtIndexPath:indexPath animated:NO];
// do double tap
}
}
由于初始滚动是光滑我尝试添加手势识别器进if (cell == nil)
条件,但他们在那里从来没有加入到细胞中。
我也是最初有加入的tableView而不是单个细胞的手势,但是这造成对取消按钮的searchDisplayController即自来水无法识别的问题。
我会appriciate任何想法,谢谢。
谢谢,我只是意识到,如果'(细胞==零)'是不正确使用的iOS5和故事,并用同样的解决方案上来作为你的第二个建议,它工作得很好。但我更喜欢你的第一个想法,我会试试看。 – steharro 2012-03-12 23:11:20