UIViewController重用Cell并更改Label内部

时间:2015-02-18 14:37:12

标签: ios objective-c uicollectionview uicollectionviewcell sigabrt

所以我的问题是我得到一个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是Classed" Karte1Zelle"。

Karte1Zelle.h

@interface Karte1Zelle : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UILabel *ZellenBeschreibung;

我确实连接了我的故事板。

UICollectionViewController到Karte1CVC

我的细胞到Karte1Zelle

那么有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

使用集合视图,您需要执行一些操作,例如添加UICollectionViewFlowLayout或注册您正在使用的单元格。 你可以用代码来完成:

 [collectionView registerClass:[Karte1Zelle class] forCellWithReuseIdentifier:@"Karte1Zelle"];