首页 > 解决方案 > 标签栏按钮抛出NSException错误,为什么?

问题描述

问题

我正在使用 Xcode 10、Swift 5。我试图重命名一些变量和数组。不过我把它们都改回了原来的名字。完成此操作后,我的标签栏按钮在 AppDelegate 处引发错误:线程 1:信号 SIGABRT

控制台输出:

2019-05-23 12:46:56.511809-0400 DIY Home Repair[1958:326215] * 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键值编码为关键的 videoImageView。*First throw call stack: (0x1d8b30518 0x1d7d0b9f8 0x1d8a4dec0 0x1d94b5a00 0x2054fb6fc 0x204d31324 0x1d8a1df38 0x204d2df7c 0x2052753a4 0x104560b80 0x104560d7c 0x20528ea38 0x20528ef38 0x20525b740 0x205278a60 0x2054fbe54 0x1dcfbe1f0 0x1dcfc3198 0x2054e7e88 0x204a3abe4 0x204a35478 0x204a33744 0x2054b8994 0x2054b8c50 0x2054c6758 0x2054c2360 0x2054b86d8 0x204a3b9e8 0x204a3bf7c 0x204a3d210 0x204a20420 0x2054fbe54 0x1dcfbe1f0 0x1dcfc3198 0x1dcf260a8 0x1dcf54108 0x1dcf54cf8 0x1d8ac189c 0x1d8abc5c4 0x1d8abcb40 0x1d8abc354 0x1dacbc79c 0x205073b68 0x10455d750 0x1d85828e0) libc++abi.dylib: 以 NSException (lldb) 类型的未捕获异常终止

试图解决问题

我检查了我所有的 segues、类名——它们与控制器匹配。我检查了所有代码以确保所有变量和数组都是准确的。我删除了从 rootTabBarController 到 ViewController 的 segue 并重新连接。我注释掉了所有代码以查看 viewController 中是否存在引发此错误的内容。我清理了构建文件夹并重新启动了 Xcode。这些都不起作用。

视图控制器的代码

请记住,我将这一切都注释掉并添加了一个空白的 viewDidLoad 函数。它仍然抛出了 NSExeption。

import UIKit

class ProductViewController: UIViewController {

    @IBOutlet weak var tableView: UITableView!

     var videos: [Video] = []

     override func viewDidLoad() {
        super.viewDidLoad()
        videos = Video.createVideoArray()
     }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

         if segue.identifier == "MasterToDetail" {
            let destVC = segue.destination as! DetailViewController
            destVC.video = sender as? Video
         }
     }
}

extension ProductViewController: UITableViewDelegate, UITableViewDataSource {

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

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

    let video = videos[indexPath.row]

    let cell = tableView.dequeueReusableCell(withIdentifier: "VideoCell") as! VideoCell
    cell.setVideo(video: video)

    return cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let video = videos[indexPath.row]
    performSegue(withIdentifier: "MasterToDetail", sender: video)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
}
}

在此处输入图像描述

标签: swiftuitabbarcontrollernsexception

解决方案


推荐阅读