ios - 由于未捕获的异常 'NSUnknownKeyException',不断出现错误/崩溃

标签 ios swift xcode

我已经检查了我的连接和类名,正如具有相同问题的所有其他线程所建议的那样。

错误消息

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key parksTableView.'

查看发生崩溃的 Controller

import UIKit

class ParksViewController: UITableView, UITableViewDataSource, UITableViewDelegate {

var parkNames = ["Sunnyside", "South Oak", "Tower", "Arno", "Arbor", "Holmes", "Brookside", "Brookside Tennis Courts", "Loose", "Gilham", "Brush Creek", "Westwood"]


@IBOutlet weak var textLabel: UILabel!
@IBOutlet weak var parksTableView: UITableView!

func viewDidLoad(){

self.parksTableView.delegate = self
self.parksTableView.dataSource = self


}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return parkNames.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    print(indexPath.row)

    cell.textLabel?.text = parkNames[indexPath.row]
    return cell
}

也许我只是没有将正确的东西连接到正确的地方?我尝试了不同连接的组合,并多次删除并重新连接连接,以尝试解决此问题,但我仍然无法理解出了什么问题。

Storyboard

Connection Inspector of ParksViewController

最佳答案

如果你查看错误,它会显示 <UIViewController 0x7fc416a04f80> 。您认为您有 ParksViewController但你真的只有一个简单的 UIViewController .

关于ios - 由于未捕获的异常 'NSUnknownKeyException',不断出现错误/崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46124363/

相关文章:

ios - 如何通过截图分享到Facebook和Twitter(社交框架)?

ios - UIAlertController 操作表中的 UIPickerView 未显示任何数据

swift - ComposableSearchablePushRow 与 Eureka 和 Swift 3

ios - 如何将 UIView 高度设置为等于两个 subview UILabel 的最大值?

ios - 通过 iOS swift 照片框架保存时如何命名照片

Xcode\Swift 中的 iOS 应用程序本地化

ios - 链接器错误: ld: symbol(s) not found for architecture x86_64

ios - 尝试在 Swift 上继承 UITableViewCell

ios - UITableViewCell IBAction 在 iOS 7 中不起作用

ios - MCSessionDelegate 要求类符合 NSObjectProtocol