xcode 如何修复错误“线程 1:EXC_BAD_ACCESS(代码 = 2,地址 = 0x7ffeeca55ff8)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/56509967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix error "Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeca55ff8)"
提问by Ryan D
I am building an app where I use a UICollectionView, but when I register my Cell, It gives me the error,
我正在构建一个使用 UICollectionView 的应用程序,但是当我注册我的 Cell 时,它给了我错误,
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeca55ff8)
线程 1:EXC_BAD_ACCESS(代码=2,地址=0x7ffeeca55ff8)
I have no idea what this means, can someone help me, please? I'm sorry if I didn't provide enough code, please ask me if u need more. Here is my code:
我不知道这是什么意思,有人可以帮我吗?很抱歉,如果我没有提供足够的代码,请询问我是否需要更多代码。这是我的代码:
import UIKit
class ThingsToDoCollectionView: UICollectionView {
override func register(_ cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String) {
register(UICollectionView.self, forCellWithReuseIdentifier: "ThingsToDoCollectionViewCell")
}
}
EDIT: here is the code for my ThingsToDoUICollectionViewCell
编辑:这是我的 ThingsToDoUICollectionViewCell 的代码
import UIKit
导入 UIKit
class ThingsToDoCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var GIDThumbnail: UIImageView!
@IBOutlet weak var GIDTitle: UILabel!
@IBOutlet weak var GIDDueDate: UILabel!
}
回答by krm
You should register the cell in the viewDidLoad method of your UIViewController which has a UICollectionView
您应该在具有 UICollectionView 的 UIViewController 的 viewDidLoad 方法中注册单元格
self.collectionView.register(UINib(nibName: "YourCellXIBFileName", bundle: nil), forCellWithReuseIdentifier: "YourCellReuseIdentifier")