我刚刚在iOS8上遇到了这个新的API。然而,我不能找到任何解决方案,如果可以使用图像,而不是文本,并允许左右刷卡?这甚至有可能吗?我发现的唯一的实现是这样的:iOS 8 UITableViewRowAction:向左滑动,图像?
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
// maybe show an action sheet with more options
[self.tableView setEditing:NO];
}];
moreAction.backgroundColor = [UIColor blueColor];
UITableViewRowAction *moreAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Button2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
}];
moreAction2.backgroundColor = [UIColor blueColor];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
return @[deleteAction, moreAction, moreAction2];
}
谢谢主席先生:-) – MichiZH 2014-09-28 07:08:02
这是一个伟大的小费,但是当我尝试它,我得到一个平铺图像。我可以为行的大小构建图像,但是我的单元格具有可变高度。如果是这种情况,有没有办法绕过它,或者我应该只使用第三方库? – skinsfan00atg 2015-02-23 21:15:24
对于图片,我放了一个CocoaPod,试图尽可能优雅地解决这个问题:https://github.com/benguild/BGTableViewRowActionWithImage – 2015-08-21 16:53:40