gpt4 book ai didi

ios - tableview 编辑模式不允许删除和/或菜单 : what is missing?

转载 作者:行者123 更新时间:2023-11-28 08:56:46 25 4
gpt4 key购买 nike

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {


@IBOutlet weak var tableView: UITableView!

var items = ["foo", "bar", "baz", "mamma mia"]

override func viewDidLoad() {
super.viewDidLoad()
self.tableView.editing = true
navigationItem.leftBarButtonItem = editButtonItem()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func tableView(table1: UITableView,
numberOfRowsInSection section: Int)
-> Int {
return self.items.count
}

// `UITableViewCell`s for each section and row
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell {
let item = self.items[indexPath.row]

let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as UITableViewCell
cell.textLabel!.text = item
return cell
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
print ("at editing style")
if editingStyle == .Delete {

print ("delete at row: \(indexPath.row)")
}
if editingStyle == .Insert {
print ("insert at row: \(indexPath.row)")

}
}

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// print ("at can edit row: \(indexPath.row)")

return true
}


func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){

}
}
  1. 为什么没有出现菜单/删除按钮?
  2. 如果它们(何时)出现,它们是否在 commitEditingStyle 中被处理?

when pressing the button no delete / menu option appears. why ?

最佳答案

实现这个方法:

func tableView(tableView: UITableView!, editingStyleForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCellEditingStyle {
return .Delete
}

关于ios - tableview 编辑模式不允许删除和/或菜单 : what is missing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32844466/

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