2017-02-08 2 views
-2

Все это хорошо, но когда я нажимаю на Tableview и пошел к теме:swift3 thread1: Сигнал 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 и видом, однако, поскольку подкласс контроллера не установлен должным образом, система пытается найти выход PhoneNumber на UIViewController и сбой.

Чтобы исправить, установите правильное имя подкласса в Interface Builder.

+0

Я переименовал проект, и до этого я не видел никаких проблем. Я проверил DetaislViewController и обнаружил, что номер телефона на выходе не был подключен, исправлен, но все еще есть проблема. –

+0

Если вы переименовали проект, убедитесь, что правильно настроили «Модуль». Это правильно под именем класса контроллера в Interface Builder. –

+0

привет, поскольку я исправил проблему с номером phonenumber, поскольку у меня не было надлежащей связи между phonenumber и представлением. после этого возникла другая проблема с lastName, не могли бы вы рассказать мне, как это сделать? –

Смежные вопросы