UIViewController 复用 Cell 并改变里面的 Label
UIViewController Reuse Cell and change Label inside
所以我的问题是我收到一个 SIGABRT 错误,其定义如下:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell ZellenBeschreibung]: unrecognized selector sent to instance 0x7fcf6b7526f0'
"Karte1CVC.m"中崩溃的部分:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Karte1Zelle *Zelle = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
Zelle.ZellenBeschreibung.Text = [Beschreibungen objectAtIndex:indexPath.item]; //----- Here the Crash happens
return Zelle;
当我删除这部分时,它可以正常工作,不会出现 SIGABRT 错误。但是我当时在屏幕上什么也看不到。
我的 UICollectionViewCell 已分类 "Karte1Zelle"。
Karte1Zelle.h
@interface Karte1Zelle : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UILabel *ZellenBeschreibung;
我确实连接了我的故事板。
UICollectionViewController 到 Karte1CVC
我的手机到 Karte1Zelle
谁能帮我解决这个问题?
对于集合视图,您必须执行一些操作,例如添加 UICollectionViewFlowLayout 或注册您正在使用的单元格。
你可以用代码来做到这一点:
[collectionView registerClass:[Karte1Zelle class] forCellWithReuseIdentifier:@"Karte1Zelle"];
所以我的问题是我收到一个 SIGABRT 错误,其定义如下:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell ZellenBeschreibung]: unrecognized selector sent to instance 0x7fcf6b7526f0'
"Karte1CVC.m"中崩溃的部分:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Karte1Zelle *Zelle = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
Zelle.ZellenBeschreibung.Text = [Beschreibungen objectAtIndex:indexPath.item]; //----- Here the Crash happens
return Zelle;
当我删除这部分时,它可以正常工作,不会出现 SIGABRT 错误。但是我当时在屏幕上什么也看不到。 我的 UICollectionViewCell 已分类 "Karte1Zelle"。
Karte1Zelle.h
@interface Karte1Zelle : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UILabel *ZellenBeschreibung;
我确实连接了我的故事板。
UICollectionViewController 到 Karte1CVC
我的手机到 Karte1Zelle
谁能帮我解决这个问题?
对于集合视图,您必须执行一些操作,例如添加 UICollectionViewFlowLayout 或注册您正在使用的单元格。 你可以用代码来做到这一点:
[collectionView registerClass:[Karte1Zelle class] forCellWithReuseIdentifier:@"Karte1Zelle"];