首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewRowAction不工作

UITableViewRowAction不工作
EN

Stack Overflow用户
提问于 2016-09-12 15:11:41
回答 2查看 1K关注 0票数 2

我有一个用UITableViewDelegateUITableViewDataSource在控制器中管理的UITableView。在这个表中,我有一个自定义的单元格,问题是editActionsForRowAtIndexPath函数只是偶尔会被调用(可能是当我以一种特定的方式输入时,我不知道),我的代码如下:

代码语言:javascript
复制
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let doneAction: UITableViewRowAction
    //let highlightAction: UITableViewRowAction
    if(self.compiti[indexPath.row].completato){
        doneAction = UITableViewRowAction(style: .Normal, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
            let compito = self.compiti[indexPath.row]
            self.db.contrassegnaCompito(compito)
            UITableViewRowAction
       }
        doneAction.backgroundColor = UIColor.redColor()
    }else{
        doneAction = UITableViewRowAction(style: .Normal, title: "Fatto") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
            let compito = self.compiti[indexPath.row]
            self.db.contrassegnaCompito(compito)
        }
        doneAction.backgroundColor = UIColor(red: 67/255, green: 160/255, blue: 71/255, alpha: 0.7)
    }
    return [doneAction]
}
EN

回答 2

Stack Overflow用户

发布于 2016-11-22 18:53:12

您还需要添加此方法实现,否则将无法滑动来显示操作

代码语言:javascript
复制
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    // it can be empty
}
票数 3
EN

Stack Overflow用户

发布于 2016-09-12 21:22:07

它适用于我的这段代码,试着从这里开始,你可能会发现什么时候出现问题

代码语言:javascript
复制
 func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    var doneAction :UITableViewRowAction!

    doneAction = UITableViewRowAction(style: .Default, title: "Da Fare") { (UITableViewRowAction, indexPath: NSIndexPath!) -> Void in
            UITableViewRowAction
    }
    return [doneAction]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39445043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档