2017-02-08 30 views
-2

一切都很好,但是当我点击的tableView去了螺纹:swift3线程1:信号SIGABRT,终止应用程序由于未捕获的异常“NSUnknownKeyException”

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(); 
      } 

     } 

    } 
} 

非常感谢!

回答

0

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

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

+0

我重命名了该项目,在此之前我没有看到任何问题。我检查了DetaislViewController,发现电话插座phoneNumber没有连接,修复,但仍然有问题。 –

+0

如果您重命名了项目,请确保正确设置“模块”。它在Interface Builder中的控制器的类名下。 –

+0

你好,因为我解决了电话号码的问题,因为我在电话号码和视图之间没有适当的联系。在那之后,它出现在lastName上的另一个问题,你能告诉我该怎么办? –

相关问题