ios - UITableViewRowAction 与 UISwipeActionsConfiguration

标签 ios swift

这两个 API 似乎得到了相同的结果。在哪种情况下使用一种优于另一种?

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
  let deleteAction = UITableViewRowAction(style: .destructive,
                                          title: "Delete") { (action, indexPath) in
    print("DELETE")
  }
  return [deleteAction]
}

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
  let DeleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: { (action, view, success) in
      print("Delete")
  })
  DeleteAction.backgroundColor = .red
  return UISwipeActionsConfiguration(actions: [DeleteAction])
}

最佳答案

它的功能基本相同,但是自 iOS 11 发布以来就可以使用滑动操作并具有一些新功能:

  • 您可以为尾部滑动和前部滑动设置 Action
  • 您可以设置 Action 图像 action.image = UIImage(...)。如果有足够的空间,它会显示图像和标题 enter image description here

此外,您应该使用滑动操作,因为它们是首选,并且在将来的更新中 UITableViewRowActions 将被弃用 UITableView 标题注释如何告诉我们:

Use -tableView:trailingSwipeActionsConfigurationForRowAtIndexPath: instead of this method, which will be deprecated in a future release.

关于ios - UITableViewRowAction 与 UISwipeActionsConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53577995/

相关文章:

ios - 如何将 CoreData 表与在线资源同步?

ios - 在 iOS 上通过 URL 方案启动 Viber 应用程序

iphone - iPhone 和 iPad 模拟器共享同一个文档文件夹吗?

ios - Xcode Swift - 如何初始化包含任意数量元素的 [[AnyObject]] 二维数组

swift - 无法将类型 '() -> _' 的值转换为指定类型 'Town.Size'

ios - UICollectionView becomeFirstResponder 错误行为

ios - AVCaptureSession commitConfiguration() 耗时太长

ios - 从 Assets 中选择它未显示在 SWIFT 的选项卡栏 Controller 中的图像

ios - 在ios中读取UTC并减去迄今为止的时间

json - 如何在 Swift 中将数组保存为 json 文件?