gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 00:50:48 26 4
gpt4 key购买 nike

我正在使用的方法

 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]
}

我还包括了

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 上放置覆盖,但随后我收到一条错误消息,指出方法未覆盖其父类(super class)中的任何方法

最佳答案

您的实现没有任何问题。该函数未被调用是因为未正确调用委托(delegate)和数据源方法。

您可以通过编程方式或通过 Storyboard连接委托(delegate)和数据源方法。

当您以编程方式实现 TableView 时,您需要在类声明中添加 UITableViewDataSource、UITableViewDelegate 并使用此代码连接委托(delegate)。

          yourTableView.datasource = self
yourTableView.delegate = self

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

Connect delegate and datasource methods via storyboard

关于ios - tableview 方法的问题 func tableView(tableView : UITableView, editActionsForRowAtIndexPath indexPath : NSIndexPath) -> [UITableViewRowAction]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38157219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com