Swift 删除表视图中的行

Swift 删除表视图中的行,swift,tableview,tablecell,Swift,Tableview,Tablecell,我最近修复了代码中的一些错误,但是出现了一个新的错误,我和我的老师都无法修复它。上面写着“预期声明” 我该如何解决这个问题 import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var StoredValues = Values() override func viewDidLoad() {

我最近修复了代码中的一些错误,但是出现了一个新的错误,我和我的老师都无法修复它。上面写着“预期声明” 我该如何解决这个问题

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 4
        }
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            self.performSegue(withIdentifier: "meunSegue", sender: self)

            func prepare(for segue: UIStoryboardSegue, sender: Any?) {
                _ = segue.destination as! SecondViewController
            }
            class SecondViewController: UIViewController {

                var recievedData = ""
                override func viewDidLoad() {
                    super.viewDidLoad()
                    print(recievedData)
                }
            }
        }
        - (void)tableView:(UITableView *)tableView committEditStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath: (NSIndexPath *)indexPath {if (editingStyle == UITableViewCellEditingStyleDelete) {
        [maTheData removeObjectAtIndex: [indexPath row]];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];


        }
    }

您试图在同一文件中混合使用Object-C和Swift。下面是您的代码的Swift 3版本

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        maTheData.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)
    }
}

寻找另一位至少具备基本知识的教师。您正在嵌套委托方法,甚至类声明。@如果您添加
var maTheData:[NSManagedObject]=[]
这只是为了向他们显示Swift文件中作为Objective-C的代码的Swift版本,它将编译。@vadian它将为我编译它不显示delete函数的方式,但你是对的,这应该是承诺。