【问题标题】:UICollectionView/AppDelegate causing crashes while following video tutorialUICollectionView/AppDelegate 在跟随视频教程时导致崩溃
【发布时间】:2020-02-26 00:37:03
【问题描述】:

在很长一段时间后回到 Swift 之后,我真的需要一个数字键盘来完成我现在的工作。我目前正在关注这个视频https://youtu.be/vI7m5RTYNng?t=319(从 5:19 开始)但是在 7:18,当他再次构建应用程序并且它工作时,我的仍然崩溃并出现同样的错误。我已经检查了 AppDelegate 中的代码至少 5 次,一切都与他的代码完全相同,直到最后一个字符。我在下面附上了我的代码。我不知道自从我第一次切换到 AppDelegate var window:UIWindow? 不存在以来,自从视频发布以来,Swift 是否发生了一些变化,我不得不自己输入。至少可以说我很沮丧。非常感谢任何帮助。

我的校对代码:

AppDelegate:

视图控制器:

错误信息:

2020-02-26 00:14:41.148993+0000 software[714:18581] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UICollectionViewController loadView] instantiated view controller with identifier "UIViewController-BYZ-38-t0r" from storyboard "Main", but didn't get a UICollectionView.'

【问题讨论】:

    标签: swift crash appdelegate


    【解决方案1】:

    错误表示您将 classUICollectionViewController 分配给 IB 中的 vc,但它是普通的 vc 而不是 UICollectionViewController 模板

    【讨论】:

    • 是的,因为我正在尝试创建一个集合视图,这就是视频中所说的。那么我现在需要做什么与视频中所说的不同?
    【解决方案2】:
    // in scene delegate
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        
        guard let _ = (scene as? UIWindowScene) else { return }
        
       //Solved Scene Code
        let layout = UICollectionViewFlowLayout()
        window?.rootViewController = UINavigationController(rootViewController: yourControllerName(collectionViewLayout: layout))
        //        
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多