首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >tableview方法func tableView(tableView: UITableView,editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]的问题?

tableview方法func tableView(tableView: UITableView,editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]的问题?
EN

Stack Overflow用户
提问于 2016-07-02 14:29:30
回答 1查看 290关注 0票数 0

我正在使用这个方法

代码语言:javascript
复制
 func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
{ 
let delete = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        //Do something
    })
    delete.backgroundColor = UIColor.redColor()

    let more = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
        //Do something
    })
    more.backgroundColor = UIColor.blueColor()

    return [delete, more]
}

我还包括了

代码语言:javascript
复制
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, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // the cells you would like the actions to appear needs to be editable
    return true
}

当我向右或向左滑动时,我创建的按钮不会出现。我尝试在editactionforrowatindexpath上设置覆盖,但随后得到一个错误,说明方法没有覆盖其超类中的任何方法

EN

回答 1

Stack Overflow用户

发布于 2016-07-02 16:41:55

在您的实现中没有任何错误。未调用该函数是因为委托和数据源方法未正确调用。

您可以通过编程或通过故事板连接委托和数据源方法。

当你以编程方式实现tableview时,你需要在类声明中添加UITableViewDataSource,UITableViewDelegate,并使用下面的代码连接委托。

代码语言:javascript
复制
          yourTableView.datasource = self
          yourTableView.delegate = self

如果你是通过storyboard实现tableview,你只需要通过拖动来连接委托和数据源方法

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38157219

复制
相关文章

相似问题

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