0

我是UICollectionView的新手。我正在尝试添加两个UILabel到我的自定义UICollectionViewCell,如下所示。将UILabel添加到自定义UICollectionViewCell不会出现在cellForItemAtIndexPath中

@interface PassCell : UICollectionViewCell 

@property (nonatomic) IBOutlet UILabel *titleLabel; 
@property (nonatomic) IBOutlet UIButton *infoButton; 
@property (nonatomic) IBOutlet UIButton *doneButton; 
@property (nonatomic) IBOutlet UILabel *headerTitle; 

我已经在StoryboardUILabel连接。 但是,当我在CellforITemAtIndexPath设置headerTitle,headerTitle UILabel不出现。只有titleLabel可以设置值。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    PassCell *cell = (PassCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"pass" forIndexPath:indexPath]; 

    cell.titleLabel.shadowColor = [UIColor blackColor]; 
    cell.titleLabel.textColor = [UIColor whiteColor]; 
    cell.titleLabel.shadowOffset = CGSizeMake(0, 1); 

    cell.titleLabel.text = @"Test"; 
    cell.headerTitle.text // That doesn't appear. 

    return cell; 
} 

我的代码有什么问题?

+0

try [cell.contentview addsubview:titlelabel]; – BHUMICA 2014-11-04 05:30:23

+0

我在Storyboard中添加了UILabel。而且我还连接了IBOutLet。但不会出现在cellForItemAtIndexPath中。 – 2014-11-04 05:31:27

+0

在cellforRow.it中以编程方式创建uilabel的作品绝对有效。 – BHUMICA 2014-11-04 05:32:45

回答

0

您必须先注册你的CustomCell cellForRow之前,方法,程序(在viewDidLoad中)

[self.collectionView registerClass:[PassCell class] forCellWithReuseIdentifier:@"pass"]; 

我不太肯定它在故事板如何做,但那里有什么错在编程这样做。

+0

这是不正确的。如果您在故事板中制作单元格,则不应注册该课程。只有在您完全使用代码完成您的单元格时才注册该类。 – rdelmar 2014-11-04 05:57:31

0

只需在storyBoard中将您的自定义类设置为collectionView Cell

相关问题