gpt4 book ai didi

ios - 为什么我看不到我的 TableViewRowActions 按钮(快速)?

转载 作者:搜寻专家 更新时间:2023-11-01 07:32:42 25 4
gpt4 key购买 nike

我想在我的表格 View 中的所有单元格上实现滑动 Action 。阅读了 4 个不同的教程后,我不明白为什么我的操作按钮没有出现:我可以进行“滑动”,我可以看到按钮应该出现的空白区域。甚至我的处理程序都不会在点击时被调用...

class RestaurantsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

@IBOutlet weak var mTableView: UITableView!

private var restosList = [Restaurant]()

override func viewDidLoad() {
super.viewDidLoad()
self.mTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")

let url = "http://xxxxxxxxxx"
Alamofire.request(.GET, url, parameters: ["service" : "restaurants"])
.responseArray { (response: [Restaurant]?, error: NSError?) in
if let response = response {
for oneResto in response {
self.restosList.append(oneResto)
}
}
self.mTableView.reloadData()
}

}

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.mTableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell

cell.textLabel?.text = self.restosList[indexPath.row].nom

return cell
}

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

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var alert:UIAlertView = UIAlertView()
alert.title = self.restosList[indexPath.row].description
alert.addButtonWithTitle("OK")
alert.show()

self.mTableView.deselectRowAtIndexPath(indexPath, animated: true)
}

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

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

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

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

return [deleteAction, moreAction]
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
// Intentionally blank. Required to use UITableViewRowActions
}

最佳答案

将 canEditRowAtIndexPath 方法添加到您的 View Controller 并返回 true。

我通常将我的处理程序代码作为闭包直接放入参数中,但我认为这不会有什么不同。

代码如下:

import UIKit

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

var myItems = ["Item 1","Item 2","Item 3"]

@IBOutlet weak var myTable: UITableView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.


}

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")

cell.textLabel?.text = myItems[indexPath.row]

return cell

}

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
// Okie dokie
}

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


let editAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Edit", handler: {

Void in

println("edit swipe")

})

let superAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Super", handler: {

Void in

println("super swipe")

})

return [editAction, superAction]

}

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


}

enter image description here

关于ios - 为什么我看不到我的 TableViewRowActions 按钮(快速)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31557845/

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