2017-03-16 116 views
0

因此,我試圖製作這個簡單的應用程序,用戶在文本字段中輸入數據,並在表格視圖中顯示這些數據。我有多個文件來定義這個應用程序的結構。但是,當我運行該應用程序,它崩潰與以下錯誤:此類不是密鑰表編碼兼容的關鍵值SWIFT 3

由於未捕獲的異常'NSUnknownKeyException'終止應用程序,原因:'[setValue:forUndefinedKey:]:此類不是密鑰編碼兼容的密鑰表。' ***第一擲調用堆棧: ( 0的CoreFoundation 0x000000011083934b exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010dc3921e objc_exception_throw + 48 2的CoreFoundation 0x0000000110839299 - [NSException提高] + 9 3基礎0x000000010d74926f - [NSObject的(的NSKeyValueCoding )的setValue:forKey:] + 291 4的UIKit 0x000000010e2a24ef - [UIViewController中的setValue:forKey:] + 88 5的UIKit 0x000000010e51679e - [UIRuntimeOutletConnection連接] + 109 6的CoreFoundation 0x00000001107de590 - [NSArray的makeObjectsPerformSelector:] + 256 7的UIKit 0x000000010e515122 - [UINib instantiateWithOwner:options:] + 186 7 8的UIKit 0x000000010e2a8c21 - [UIViewController中_loadViewFromNibNamed:束:] + 386 9的UIKit 0x000000010e2a9543 - [UIViewController中的loadView] + 177 10的UIKit 0x000000010e5291ca - [的UITableViewController的loadView] + 84 11的UIKit 0x000000010e2a9878 - [UIViewController中loadViewIfRequired] + 201 12 UIKit的0x000000010e2aa0cc - [UIViewController的視圖] + 27 13的UIKit 0x000000010e173c51 - [一個UIWindow addRootViewControllerViewIfPossible] + 71 14的UIKit 0x000000010e1743a2 - [一個UIWindow _setHidden:強制:] + 293 15的UIKit 0x000000010e187cb5 - [一個UIWindow makeKeyAndVisible] + 42 16的UIKit 0x000000010e100c89 - [UIApplication _callInitializationDelegatesForMainScene:t ransitionContext:] + 4818 17的UIKit 0x000000010e106de9 - [UIApplication的_runWithMainScene:transitionContext:完成:] + 1731 18的UIKit 0x000000010e103f69 - [UIApplication的workspaceDidEndTransaction:] + 188個 19 FrontBoardServices 0x0000000111ef7723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24個 20 FrontBoardServices 0x0000000111ef759c - [FBSSerialQueue _performNext] + 189個 21 FrontBoardServices 0x0000000111ef7925 - [FBSSerialQueue _performNextFromRunLoopSource] + 45 22的CoreFoundation 0x00000001107de311 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 23的CoreFoundation 0x00000001107c359c __CFRunLoopDoSources0 + 556 24的CoreFoundation 0x00000001107c2a86 __CFRunLoopRun + 918 25的CoreFoundation 0x00000001107c2494 CFRunLoopRunSpecific + 420 26的UIKit 0x000000010e1027e6 - [UIApplication的_run] + 434 27的UIKit 0x000000010e108964 UIApplicationMain + 159 28晨星2 0x000000010d6531bf主+ 111 29 libdyld.dylib 0x000000011176668d啓動+ 1 ) 的libC++ abi.dylib:與類型NSException

的未捕獲的異常終止這是我EventBrain.swift文件:

import Foundation 


struct Event{ 

    var title:String? 
    var location:String? 

    init(tits: String, locs: String){ 
     self.title = tits 
     self.location = locs 
    } 
} 

這是我的viewController。SWIFT文件:

import UIKit 

class ViewController: UIViewController { 


    @IBOutlet weak var txtTitle: UITextField! 

    @IBOutlet weak var txtLocation: UITextField! 

    @IBOutlet weak var txtDate: UITextField! 

    @IBOutlet weak var txtTime: UITextField! 

    var eventsArray = [Event]() 


    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

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


    @IBAction func btnSave() { 

     let event = Event(tits: txtTitle.text!, locs: txtLocation.text!) 

     eventsArray.append(event) 

    } 
} 

這是我EventsTable.swift文件:

import UIKit 

class EventsTable: UITableViewController { 

var tableData = ViewController() 

override func viewDidLoad() { 
    super.viewDidLoad() 

    // Uncomment the following line to preserve selection between presentations 
    // self.clearsSelectionOnViewWillAppear = false 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem() 
} 

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

// MARK: - Table view data source 

/* 
override func numberOfSections(in tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    return 0 
} 
*/ 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    return tableData.eventsArray.count 
} 


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    //let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomeCell 

    cell.title.text = tableData.eventsArray[indexPath.row].title 

    cell.location.text = tableData.eventsArray[indexPath.row].location 

    return cell 

    } 
} 

這是我customeCell.swift文件:

import UIKit 

class CustomeCell: UITableViewCell { 

override func awakeFromNib() { 
    super.awakeFromNib() 
    // Initialization code 
} 

override func setSelected(_ selected: Bool, animated: Bool) { 
    super.setSelected(selected, animated: animated) 

    // Configure the view for the selected state 
} 


@IBOutlet weak var title: UILabel! 

@IBOutlet weak var location: UILabel! 

} 

最後這裏是我的main.Storyboard:

Main.Storyboard

回答

0

通常情況下,當您在InterfaceBuilder中連接IBOutlet時會發生這種情況,然後刪除定義插座的代碼。

問題是故事板/ XIB文件嘗試使用KVC(鍵值編碼)來引用視圖控制器的出口屬性,但它不再存在,所以KVC調用會崩潰。

通過您的故事板/ xibs查看具有不再存在的插座「表」的場景/視圖控制器。

相關問題