我有一个表格视图,每个单元格上都有一个标签和两个按钮。目前我有这段代码可以通过滑动来删除。
- (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.
}
}
当我滑动时,此代码就会执行。但我希望它在按下按钮时执行。该按钮与以下 IBAction 链接。
- (IBAction)deleteRow:(id)sender {
//Delete row
}
要记住一件事。我希望删除按钮像滑动删除时那样滑动。
有谁能够帮助我?
如果您的按钮位于单元格中,您可以将其 tag 属性设置为 indexPath.row 值,并为其分配目标的 deleteRow:(id)sender 方法-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents
为了让按钮滑动,您可能需要实现 panGestureRecognizer。我对此可能是错的,但这个想法应该是检测触摸位置并滑动按钮(在滑动时设置其框架)。如果您打算通过滑动按钮进行删除,则可能需要禁用表格上的滑动删除功能。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)