2015-02-09 79 views
1

我有兩種類型UICollectionViewCell:一類是畫廊細胞,另一種是配方細胞。我們如何爲單個UICollectionView使用兩種類型的UICollectionViewCell?

有一個切換按鈕。 首次加載視圖時,圖庫單元格將用於在集合視圖中顯示。

但在點擊切換按鈕,我試圖加載另一個單元:(配方單元),但它崩潰說沒有物業(其實這是配方細胞的財產)圖庫細胞。

有沒有辦法來加載與其他細胞相同的集合視圖?

在此先感謝。

編輯:

if (isGalleryOnCollectionView) { 

    ProfileFollowerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 

    NSString *followerName; 

    if ([[arr_followerNames objectAtIndex:indexPath.row] isEqualToString:@""]) { 
     followerName=[arr_followersEmail objectAtIndex:indexPath.row]; 
    } 
    else{ 
     followerName=[arr_followerNames objectAtIndex:indexPath.row]; 
    } 

    NSLog(@"\n\n\n follower name is :: %@\n\n",followerName); 

    cell.lbl_followerName.text = followerName; 

}else{ 

     GalleryCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath]; 


     cell.lbl_recipeName.text = [[[dict_profileData valueForKey:@"recipes"] valueForKey:@"name"] objectAtIndex:indexPath.row]; 


} 

SOLUTION:

[self.profleCollectionView registerClass:[ProfileFollowerCell class] forCellWithReuseIdentifier:@"followercell"]; 

出隊它的工作原理可重複使用的標識符之前,從筆尖註冊之後。

+1

郵政代碼' - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath'正在返回 – random 2015-02-09 16:26:57

+0

@random,如果我加載一個類型的細胞說ProfileFollowerCell在集合視圖,如果我重裝的CollectionView,並嘗試使用它崩潰下一個單元格(它使用舊電池) – user3804063 2015-02-09 16:36:32

+0

我試着重裝之前做出的CollectionView爲零,但不作品 – user3804063 2015-02-09 16:37:06

回答

3

Here is a good tutorial on creating custom UICollectionViewCell with xibs.

什麼你缺少的是在你的-(void)viewDidLoad

UINib *cellNib = [UINib nibWithNibName:@"ProfileFollowerCellNib" bundle:nil]; 
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"TheNibCellIdentifier"]; 

也有這個,你需要確保裝載電池時使用的各ReuseIdentifier

ProfileFollowerCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TheNibCellIdentifier" forIndexPath:indexPath]; 
+0

電池我也想通了這一點,但無論如何感謝連接原型細胞,也感謝pointin g我的重用標識符。 – user3804063 2015-02-09 16:52:57

相關問題