ios - iOS 11 之前的行操作

标签 ios objective-c uitableview

我正在尝试向表格 View 中的一行添加一个 Action (通过滑动)。由于缺陷,我可以使用此方法删除:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
}

但我不知道如何进行自定义操作。我读到他们在 iOS 11 中引入了它。如果我也需要它用于以前的版本怎么办?

这是 iOS 11 的方法:

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath

如您所见,我使用的是 iOS 11。所以,为了清楚起见,我希望用户滑动一行以显示一个 Action (具有不同颜色的背景和文本)。我不关心它出现的形式(尾随或前导)。

最佳答案

So, to make it clear, I want the user to swipe a row to show an action (with different color background and a text). I don't care form where it appears (trailing or leading).

这样做

-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{

  UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"  Delete  " handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                // your delete mechanism here
            }];
   deleteAction.backgroundColor = [UIColor redColor];
        return @[deleteAction];

    }

关于ios - iOS 11 之前的行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48784515/

相关文章:

ios - 当使用 "share"功能时,在标题中输入什么来包含用户的新分数?

ios - 使用 TrailingSwipeActionsConfigurationForRowAt 删除单元格时出现一些奇怪的动画错误

ios - 如何将cocoapod添加到ios框架

ios - UISearchBarDelegate 和 textFieldShouldClear 替代方案

ios - 将 Obj C 转换为 Swift 错误 :type of expression is ambiguous without more context

ios - 更改 iOS 日期选择器显示格式

objective-c - 快速解决 Appestore 拒绝 XMPP iOS VoIP 后台执行的问题

iphone - iOS 错误 : No visible @interface for 'Project' declares the selector 'alloc'

uitableview - Swift UITableView 在视觉上取消选择滚动上的单元格

ios - 如何通过 stackview 将图像添加到 tableview 单元格