代码之家  ›  专栏  ›  技术社区  ›  saravanar

tableview在“didselect”事件上显示更多选项

  •  0
  • saravanar  · 技术社区  · 7 年前

    如何在上显示uitableview的swipe选项 didselectRow:

    想显示如下的刷卡选项。 enter image description here

    exmaple在图中显示,这应该在didselect行中实现。这对我有什么帮助。谢谢提前。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Junior Jiang    7 年前

    首先,你应该确保:

    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // the cells you would like the actions to appear needs to be editable
        return true
    }
    
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        // you need to implement this method too or you can't swipe to display the actions
    }
    

    其次,您将在此委托方法中实现:

    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
        let more = UITableViewRowAction(style: .Normal, title: "More") { action, index in
            println("more button tapped")
        }
        more.backgroundColor = UIColor.lightGrayColor()
    
        let favorite = UITableViewRowAction(style: .Normal, title: "Favorite") { action, index in
            println("favorite button tapped")
        }
        favorite.backgroundColor = UIColor.orangeColor()
    
        let share = UITableViewRowAction(style: .Normal, title: "Share") { action, index in
            println("share button tapped")
        }
        share.backgroundColor = UIColor.blueColor()
    
        return [share, favorite, more]
    }
    

    最后的景象是这样的: enter image description here 希望这对你有帮助。

    推荐文章