Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/94.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 添加UINavigationController时崩溃-swift_Ios_Swift_Storyboard - Fatal编程技术网

Ios 添加UINavigationController时崩溃-swift

Ios 添加UINavigationController时崩溃-swift,ios,swift,storyboard,Ios,Swift,Storyboard,添加UINavigationController时崩溃。 我正在使用此库和示例代码: Xcode错误日志: Class AppstoreTransition.CardPresentationController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API. Could not

添加UINavigationController时崩溃。 我正在使用此库和示例代码:

Xcode错误日志:

Class AppstoreTransition.CardPresentationController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.
Could not cast value of type 'UINavigationController' (0x1049b1338) to 'AppstoreTransition.CardsViewController' (0x1049b1308).
2019-06-29 15:39:24.077448+0200 TechSpec[10118:1200941] Could not cast value of type 'UINavigationController' (0x1049b1338) to 'AppstoreTransition.CardsViewController' (0x1049b1308).

第一名:

强制展开值(使用!)通常是不好的做法,大多数情况下可以(也应该)避免。如果没有任何东西可以展开,强制展开保证会使你的应用程序完全崩溃(无)

相反,你应该使用类似if let或guard let的东西,例如


guard let cell=collectionView.cellForItem(at:indexPath)作为?CardCollectionViewCell else{debugPrint("哦,这里的nil听起来像是你的子类覆盖了
traitCollection
,它说这是不允许的。@DanielStorm你知道如何解决它吗?实际的问题是演员问题。最有可能的是你的故事板声称UINavigationController实际上是一个CardsViewController,而实际上它不是。这是一个您确实希望强制展开(强制转换)。单元格应该是已知类型,强制转换应该是您所做的。如果转换失败,您希望应用程序在开发过程中尽早崩溃,以便您可以修复代码。请注意,错误与单元格无关。它是关于将UINavigationController转换为CardsViewController。问题中的代码与实际问题。你是对的,代码与错误无关。但解决方案可能类似于我发布的屏幕截图。在早期开发期间使用强制转换可能是好的,而且在许多教程中也显示了强制展开自定义单元格内容。但是如果强制转换没有失败怎么办?你不能说它永远不会失败在用户的设备上。我认为处理所有可能的情况,而不是仅仅为了保存一些代码字符而给应用程序一个崩溃的机会,这是一个很好的做法。
Class AppstoreTransition.CardPresentationController overrides the -traitCollection getter, which is not supported. If you're trying to override traits, you must use the appropriate API.
Could not cast value of type 'UINavigationController' (0x1049b1338) to 'AppstoreTransition.CardsViewController' (0x1049b1308).
2019-06-29 15:39:24.077448+0200 TechSpec[10118:1200941] Could not cast value of type 'UINavigationController' (0x1049b1338) to 'AppstoreTransition.CardsViewController' (0x1049b1308).