繁体   English   中英

快速编辑UITableView

[英]Editable UITableView in swift

如何使UITableview可编辑,我正在使用EDITActionsForRowAtIndexPath委托来编辑单元格
我的代码:

let infoAction = UITableViewRowAction(style: UITableViewRowActionStyle.Destructive, title: "More", handler: { (action , indexPath) -> Void in
            let MoreInfo = UIAlertController(title: "More", message: nil, preferredStyle: .ActionSheet)

            MoreInfo.addAction((UIAlertAction(title: "Flag This conversation", style: .Default, handler: { (UIAlertAction) -> Void in
                print("flaged")
                self.tableView.setEditing(true, animated: true)
                self.tableView.editing = true
            })))


            MoreInfo.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
            print("Cancel")
            self.presentViewController(MoreInfo, animated: true, completion: nil)
        })

不要使用uialert,请尝试以下代码段:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {

    let deleteClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        println("Delete button pressed")
    }

    let moreClosure = { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
        println("More button pressed")
    }

    let deleteAction = UITableViewRowAction(style: .Default, title: "Delete", handler: deleteClosure)
    let moreAction = UITableViewRowAction(style: .Normal, title: "More", handler: moreClosure)

    return [deleteAction, moreAction]
}

该按钮应显示2个按钮:一个红色(带有删除文本)和一个灰色(带有更多文本); 您可以根据自己的喜好进行自定义:)

来源: http//pablin.org/2014/09/25/uitableviewrowaction-introduction/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM