1
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){
}
}
- 爲什麼菜單/刪除按鈕沒有出現?
- 如果(何時)出現,它們是否在commitEditingStyle處理?
做到這一點,但仍然沒有改變。當按下「 - 」按鈕時,行內容變爲空白,並且不會出現刪除/其他選項。使用Xcode 7.0(7A121I) –
OOps。發現問題。 –
對不起:問題是AUTOLAYOUT。一旦我解決了約束條件,信息就會按照需要顯示。感謝您的幫助.... –