简体   繁体   English

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

[英]How can i swipe on a table cell and make it call a function?

How can i swipe my finger on a table cell and call a function ( in which i push a view controller to my navigation controller )?我如何在表格单元格上滑动手指并调用 function (在其中我将视图 controller 推送到我的导航 controller )?

Just add a UISwipeGestureRecognizer to the cell.只需将UISwipeGestureRecognizer添加到单元格。

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];
}

Then implement the method to handle the swipe:然后实现处理滑动的方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM