swift3 thread1:信号SIGABRT,由于未捕获的异常终止应用程序' NSUnknownKeyException'

时间:2017-02-08 01:42:04

标签: ios swift3 xcode8

一切都很好但是当我点击tableView并进入主题时:

thread1:Signal SIGABRT, '[<UIViewController 0x7fc3c0c0b730> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lastName.'

AppDelegate.swift,错误就行了:class AppDelegate: UIResponder, UIApplicationDelegate

import UIKit  

@UIApplicationMain  
class AppDelegate: UIResponder, UIApplicationDelegate {  

    var window: UIWindow?  

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {  
        // Override point for customization after application launch.  
        return true  
    }  

    func applicationWillResignActive(_ application: UIApplication) {  
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}

DetailsViewController.swift,点击tableview后,应该转到detailView并在表格中显示数据的详细信息

import UIKit

class DetailsViewController: UIViewController {

    var st:Student?


    @IBOutlet weak var stName: UILabel!
    @IBOutlet weak var lastName: UILabel!
    @IBOutlet weak var phoneNumber: UILabel!
    @IBOutlet weak var studentId: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        stName.text=st?.fName;
        lastName.text=st?.lName;
        phoneNumber.text=st?.phoneNum;
        studentId.text=st?.id;

    }

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

}

TableViewController.swift,还有一个问题,@IBAction func myUnwindAction(segue:UIStoryboardSegue)有什么问题?

import UIKit

class TableTabViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {


    @IBOutlet weak var dataTable: UITableView!
    @IBOutlet var barButton   : UIBarButtonItem?


    override func viewDidLoad() {
        super.viewDidLoad()
        dataTable.delegate=self;
        dataTable.dataSource=self;

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }


    @IBAction func myUnwindAction(segue: UIStoryboardSegue)
    {

        if let temp = segue.source as? NewStudentViewController{
            if (temp.exitBool != true){
                StudentDataBase.instance.addStudent(st: temp.st!);
                dataTable.reloadData();
            }
        }

    }



    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return StudentDataBase.instance.getNumberOfStudents();
    }


    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell=UITableViewCell();
        cell.textLabel?.text=StudentDataBase.instance.getStudentByIndex(index: indexPath.row).getFullName();
        return cell;
    }


    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        performSegue(withIdentifier: "details", sender: StudentDataBase.instance.getStudentByIndex(index: indexPath.row));
    }


    override func prepare(for segue: UIStoryboardSegue, sender: Any? ){
        if let detailsController=segue.destination as? DetailsViewController{
            detailsController.st=sender as? Student;
        }


    }


    @IBAction func editTableView (_ sender:UIBarButtonItem)
    {
        if dataTable.isEditing{
            //listTableView.editing = false;
            dataTable.setEditing(false, animated: true);
            barButton?.style = UIBarButtonItemStyle.plain;
            barButton?.title = "Edit";
            //listTableView.reloadData();
        }
        else{
            //listTableView.editing = true;
            dataTable.setEditing(true, animated: true);
            barButton?.title = "Done";
            barButton?.style =  UIBarButtonItemStyle.done;
            //listTableView.reloadData();
        }
    }

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
    {
        if editingStyle == UITableViewCellEditingStyle.delete{
            if(StudentDataBase.instance.deleteStudent(ids: StudentDataBase.instance.getStudentByIndex(index: indexPath.row).id!))
            {
                self.editTableView(barButton!);
                dataTable.reloadData();
            }

        }

    }
}

非常感谢!

1 个答案:

答案 0 :(得分:0)

您在Interface Builder中错误地设置了自定义视图控制器子类。 (也许,你重命名了这个类?)所以它回到了父UIViewController。 请注意调试器输出中的“未知类”警告。 由于在PhoneNumber属性和视图之间设置了插座而发生崩溃,但由于控制器子类设置不正确,系统会尝试在PhoneNumber上找到UIViewController插座,崩溃。

要修复,请在Interface Builder中设置正确的子类名称。