【发布时间】:2017-09-30 09:24:14
【问题描述】:
我正在制作一个表格视图,我想制作一个功能,您可以通过向右滑动并点击删除按钮来删除一行。我和我的老师已经尝试了大约半个小时来解决这个问题,但似乎没有任何效果。
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var StoredValues = Values()
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {//
super.didReceiveMemoryWarning()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return UITableViewCell()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "meunSegue", sender: self)
func prepare(for segue: UIStoryboardSegue, sender: Any?) {
_ = segue.destination as! SecondViewController
}
}
func tableView->(UITableView *)tableView canEditRowsAtIndexPath:(NSIndexPath *)indexPath {
return YES
}
- (void)tableView:(UITableView *)tableView committEditStyle: (UITableViewCellEditingStyle)
func tableView {
var cell = UITableView.self
var Animation = UITableViewRowAnimation(rawValue: 1)
if editingStyle == UITableViewCellEditingStyle.delete {
cell.deleteRows(indexPath)
//cell.deleteRows(at: [NSIndexPath], with: UITableViewRowAnimation.automatic)
}
}
class SecondViewController: UIViewController {
var recievedData = ""
override func viewDidLoad() {
super.viewDidLoad()
print(recievedData)
}
}
}
【问题讨论】:
-
您的源代码是 Swift 和 Objective-C 的奇怪组合。您可以清理您的示例代码,以便它使用更好的代码编译和编辑您的问题。
标签: swift tableview tableviewcell