我尝试向Swipe Action添加图标,但我找不到任何解决方案。有人说"使用&traffingSwipeActionsConfigurationForRowAt'无法实现' trailingSwipeActionsConfigurationForRowAt' &#34 ;.这是真的还是有任何解决方案?谢谢你的回复。
答案 0 :(得分:2)
尝试这样
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let deleteAction = UIContextualAction(style: .normal, title: "", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
// Your Call Here
success(true)
})
deleteAction.image = UIImage(named: "Trash")
deleteAction.backgroundColor = COLOR_ORANGE
return UISwipeActionsConfiguration(actions: [deleteAction])
}
答案 1 :(得分:-1)
在此代码中,您可以添加有助于您的自定义逻辑。这适用于ios 11.
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:@"DELETE"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSLog(@"index path of delete: %@", indexPath);
completionHandler(YES);
}];
UIContextualAction *rename = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal
title:@"RENAME"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
NSLog(@"index path of rename: %@", indexPath);
completionHandler(YES);
}];
UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[rename, delete]];
swipeActionConfig.performsFirstActionWithFullSwipe = NO;
return swipeActionConfig;
}
我希望这会对你有所帮助
由于