我想在我的表格视图中的所有单元格上实现滑动运动。在阅读了 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
}