2013-08-18 232 views
-1

我已经加入另一UICollectionViewCell到我UICollectionView如图所示:麻烦与UICollectionViewCell

Storyboard Image

每一个被连接到一个不同的类黄一个被连接到一个称为的ImageCell和蓝色一个类被连接到一个名为TwitterCell的类。图像单元应该显示一个Instagram的图片与UIImageView(现在BTW工作正常)。不过,我想在TwitterCell下添加其他单元,它应该用UILabel显示用户的Twitter推文。这里是我的代码现在:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    ImageCell *cell = (ImageCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"imageCell" 
                      forIndexPath:indexPath]; 
    NSURL *url = [self imageUrlForEntryAtIndexPath:indexPath]; 
    //NSLog(@"%@", url); 
    [cell.imageView setImageWithURL:url]; 
    cell.backgroundColor = [UIColor whiteColor]; 

    TwitterCell *tweetCell = (TwitterCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"twitterCell" forIndexPath:indexPath]; 


    return cell; 
    return tweetCell; 
} 

这里是我到底想要什么形象(记住一切都按时间排序发布):

Final Product Image

+0

你问这个问题之前(http://stackoverflow.com/questions/18284955/how-would-you-add-two-different-uicollectionviewcells),并且显然没有任何尝试改变你的代码的基础上我的答案在那里。 – rdelmar

回答

1

记住registerClass:forCellWithReuseIdentifier:为了让出列工作正常工作。此外,您只能回答cellForItemAtIndexPath中的一个单元格:检查该行是偶数还是奇数以决定要出列哪种类型的单元格,然后仅初始化该单元格的内容。

+0

你能告诉我如何构建代码来检查行是偶数还是奇数 – Prad

+0

如果'indexPath.row%2 == 0',则该行是偶数。 –