单击一个button,replace轻扫的操作

我有一个标签和每个单元格上的两个button的桌面视图。 目前,我有这个代码,做一个刷卡删除。

- (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [appointments removeObjectAtIndex: indexPath.row]; // manipulate your data structure. [tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation: UITableViewRowAnimationFade]; NSLog(@"row deleted"); // Do whatever other UI updating you need to do. } } 

这个代码在我滑动时得到执行。 但是我希望它在按下button时执行。 该button与以下IBAction相关联。

 - (IBAction)deleteRow:(id)sender { //Delete row } 

有一点要记住。 我希望删除button可以像滑动删除时一样滑动。

有谁能够帮助我?

如果你的button在单元格中,你可以将它的标签属性设置为indexPath.row值,并通过-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents为目标分配deleteRow:(id)sender方法-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents为了让button滑动,您可能需要实现panGestureRecognizer。 我可能是错误的,但这个想法应该是非常多的检测触摸位置和滑动button(设置其框架滑动)。 如果您的目的是通过滑动button来删除,您可能需要禁用滑动删除表上。