Ios 在UITableViewCell上向右滑动
所以我在这个网站上搜索了这个问题的答案,有一些不错的结果,但没有什么最新的,因为XCode 7不再是beta版,swift 2.0现在是标准版 我使用了以下代码,以便“向左滑动”功能会导致UITableViewCell发生某些事情-Ios 在UITableViewCell上向右滑动,ios,swift,uitableview,swipe,Ios,Swift,Uitableview,Swipe,所以我在这个网站上搜索了这个问题的答案,有一些不错的结果,但没有什么最新的,因为XCode 7不再是beta版,swift 2.0现在是标准版 我使用了以下代码,以便“向左滑动”功能会导致UITableViewCell发生某些事情- func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSI
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){
if editingStyle == UITableViewCellEditingStyle.Delete {
....
}
}
我知道这是Apple现在在API中提供的,不需要使用外部类
我还了解到,您可以使用以下本机代码自定义此刷卡产生的操作:
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in
print("more button tapped")
}
我的问题是,是否还有任何本机代码(iOS 9.0+,swift 2.0)可以定义UITableViewCell上的“右击”
提前谢谢你 否,目前还没有此类本机API。此功能在iOS 11.0+和Mac Catalyst 13.0+上可用。对于左侧的选项,请使用前导方法;对于右侧的选项,请使用尾随方法
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let closeAction = UIContextualAction(style: .normal, title: "Close", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("OK, marked as Closed")
success(true)
})
closeAction.image = UIImage(named: "tick")
closeAction.backgroundColor = .purple
return UISwipeActionsConfiguration(actions: [closeAction])
}
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let modifyAction = UIContextualAction(style: .normal, title: "Update", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Update action ...")
success(true)
})
modifyAction.image = UIImage(named: "hammer")
modifyAction.backgroundColor = .blue
return UISwipeActionsConfiguration(actions: [modifyAction])
}
只需实现UITableViewDelegate方法并返回UISwipeActionsConfiguration对象。您可以选择包含图像或仅包含文本作为按钮的标题
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
确保在数据源代理中启用编辑,否则将禁用滑动选项
// True for enabling the editing mode
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
可能重复的尝试自定义刷删除@NANNAV耶看起来这是唯一的方法done@Anbu.Karthik是的,我希望那篇文章会有一些新的发展,但看起来不像是谢谢你!奇怪的是,他们会包含用于添加“左扫”值的本机API,而且奇怪的是,他们在邮件应用程序中有一个“右扫”的清晰示例,但在API中没有提供:(我自己无法解释它,但是我猜想它会随着下一个更新而到来,同时通过授予对这些视图的子类的访问来扩展这个API,并且因此允许更好地定制与IGIVESE。请考虑评论您的答案,以便其他人更容易掌握。请添加解释,以便其他人能够理解。nd!