一段 iOS Swift 的 editActionsForRowAtIndexPath [英] editActionsForRowAtIndexPath for one section iOS Swift

查看:33
本文介绍了一段 iOS Swift 的 editActionsForRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您在图像中看到的,此 tableView 中有两个部分.我可以知道如何仅在第一部分启用 editActionsForRowAtIndexPath 吗?

As you can see in the images, there are two sections in this tableView. May I know how to manage to enable the editActionsForRowAtIndexPath in section one only?

这是我的代码,它使 tableViewCell 能够进行行滑动...

Here is my code that enable the tableViewCell to have a row swipe...

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{
    let complete =  UITableViewRowAction(style: .Normal, title: "Complete")
    { action, index in
        print("more button tapped")
    }
    complete.backgroundColor = UIColor.greenColor()
    return [complete]
}

推荐答案

你可以使用 indexPath.section 来决定你设置的是哪个部分,但你应该使用 tableView:canEditRowAtIndexPath:indexPath: 来告诉要启用编辑时的表格视图.

You can use indexPath.section to decide which section you are setting, but you should use tableView:canEditRowAtIndexPath:indexPath: to tell the table view when you want to enable editing.

Swift 2

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool{
    return indexPath.section == 0
}

Swift 3

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return indexPath.section == 0
}

这篇关于一段 iOS Swift 的 editActionsForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆