gpt4 book ai didi

ios - NSUnknownKeyException UICollectionView

转载 作者:行者123 更新时间:2023-11-28 12:36:11 25 4
gpt4 key购买 nike

我最近为我的应用实现了一个新 View ,它有一个 UICollectionView 作为要加载的图像的网格:

class MemoriesView: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource{

@IBOutlet weak var images_collection: UICollectionView!

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

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.navigationController?.navigationBarHidden = false
}

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

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 12
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("memory_image_1", forIndexPath: indexPath) as! CollectionViewController
return cell
}

}

现在这个类中的代码很可能是完全颠倒的,因为我必须遵循这个教程。所以这里没有采取个人主动行动。因此,当我尝试进入此 View 时可能会产生此错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Certi.MemoriesView 0x7fb613f3c8d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageCollectionView.'

*** First throw call stack:
(
0 CoreFoundation 0x000000010ee6ae65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010f2c7deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ee6aaa9 -[NSException raise] + 9
3 Foundation 0x000000010cfb29bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x000000010d98c320 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010dbbaf41 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010edab4a0 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010dbb9924 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x000000010d992eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x000000010d993816 -[UIViewController loadView] + 178
10 UIKit 0x000000010d993b74 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x000000010d999f4f -[UIViewController __viewWillAppear:] + 120
12 UIKit 0x000000010d9c9e44 -[UINavigationController _startCustomTransition:] + 1203
13 UIKit 0x000000010d9da23f -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
14 UIKit 0x000000010d9db3af -[UINavigationController __viewWillLayoutSubviews] + 57
15 UIKit 0x000000010db81ff7 -[UILayoutContainerView layoutSubviews] + 248
16 UIKit 0x000000010d8b44a3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
17 QuartzCore 0x000000011101459a -[CALayer layoutSublayers] + 146
18 QuartzCore 0x0000000111008e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
19 QuartzCore 0x0000000111008cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
20 QuartzCore 0x0000000110ffd475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
21 QuartzCore 0x000000011102ac0a _ZN2CA11Transaction6commitEv + 486
22 UIKit 0x000000010d7f7f7c _UIApplicationHandleEventQueue + 7329
23 CoreFoundation 0x000000010ed96a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x000000010ed8c95c __CFRunLoopDoSources0 + 556
25 CoreFoundation 0x000000010ed8be13 __CFRunLoopRun + 867
26 CoreFoundation 0x000000010ed8b828 CFRunLoopRunSpecific + 488
27 GraphicsServices 0x00000001115d7ad2 GSEventRunModal + 161
28 UIKit 0x000000010d7fd610 UIApplicationMain + 171
29 Certi 0x000000010b92c1fd main + 109
30 libdyld.dylib 0x000000010fde392d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

最佳答案

我怀疑您确实将我们的 IBOutlet imageCollectionView 重命名为 images_collection,但没有在 Storyboard 中更新它。

解决这个问题:

  • 在 Storyboard 中右键单击您的 imageCollectionView
  • 通过单击小“x”按钮删除指向Memories View 的链接

  • 通过从代码中的 IBOutlet 拖动到 Storyboard中的 imageCollectionView 来创建新链接

关于ios - NSUnknownKeyException UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40739424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com