Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在表格单元格上滑动并使其调用函数?_Iphone_Ios_Cocoa Touch - Fatal编程技术网

Iphone 如何在表格单元格上滑动并使其调用函数?

Iphone 如何在表格单元格上滑动并使其调用函数?,iphone,ios,cocoa-touch,Iphone,Ios,Cocoa Touch,如何在表格单元格上滑动手指并调用函数(将视图控制器推送到导航控制器) 只需在单元格中添加一个uisweegesturecognizer UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaul

如何在表格单元格上滑动手指并调用函数(将视图控制器推送到导航控制器)

只需在单元格中添加一个
uisweegesturecognizer

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    UISwipeGestureRecognizer *g = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellWasSwiped:)];
    [cell addGestureRecognizer:g];
    [g release];
}
然后实现处理刷卡的方法:

- (void)cellWasSwiped:(UIGestureRecognizer *)g {
    NSLog(@"Swiped");
}

似乎您还需要设置这个,
g.direction=uisweepGestureRecognitizerDirectionLeft您可能还需要添加:
CGPoint=[GestureRecognitor locationInView:TableView];NSIndexPath*indexPath=[TableView indexPathForRowAtPoint:p];如果(indexPath==nil){//Not on a cell}或者{//on a cell,请使用indexPath执行操作。}
@NightLeopard在本例中,手势识别器添加到单元格本身,因此如果触发,它始终来自单元格。将手势识别器添加到单元格本身有什么意义,尽管如此?这样做意味着你无法分辨哪个手机被刷过。只为整个表视图创建一个并动态获取单元格更容易,CPU和内存效率更高。@NightLeopard手势识别器有一个
视图
属性,其中包含它附加到的视图,在本例中是表视图单元格。至于效率,最好为表视图本身设置识别器,但只有仪器才能识别。:)