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

相關問題