在UITableViewCell上滑动

时间:2016-12-23 09:48:46

标签: swift xcode swift3 tableview cell

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
}

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let more = UITableViewRowAction(style: .normal, title: "More") { action, index in
        print("more button tapped")
    }
    more.backgroundColor = UIColor.lightGray

    let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
        print("favorite button tapped")
    }
    favorite.backgroundColor = UIColor.orange

    let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
        print("share button tapped")
    }
    share.backgroundColor = UIColor.blue

    return [share, favorite, more]
}

我已插入此代码以在单个Cell上创建一些操作,但是当我运行项目并尝试在单元格上滑动时,唯一可能的操作是Delete

如何解决此问题?

1 个答案:

答案 0 :(得分:2)

tableView(_:editActionsForRowAt:)的签名在Swift 3中更改为如下所示。只需将您的func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { let more = UITableViewRowAction(style: .normal, title: "More") { action, index in print("more button tapped") } more.backgroundColor = UIColor.lightGray let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in print("favorite button tapped") } favorite.backgroundColor = UIColor.orange let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in print("share button tapped") } share.backgroundColor = UIColor.blue return [share, favorite, more] } 替换为低于一个。

mvn tomcat6:run