2012-11-06 137 views
4

我最近增加了一个UICollectionView我的故事板,它目前由另一视图推入视图,这似乎然而,工作正常使用故事板编辑,我视图设置为包含35个细胞,其在编辑器中的样子好,但是当我运行应用程序时,单元格是不可见的。一些单元格里面有UIButtons,它们也不会渲染。UICollectionView细胞是无形

仔细检查有人渲染我改变了编辑器的背景颜色,并再次运行它,正确地更新了颜色。我是否正确地假设安装程序应该自动呈现单元格,而不必运行任何委托代码(如果它们已在编辑器中进行设置)?

任何帮助,将不胜感激。

由于

EDIT ----

确定我已实施在我的第二视图控制器适当的委托方法其然后推动一个SEGUE弹出的CollectionView控制器,I还增加了我的第二视图控制器头文件和下面的代码添加到.M文件:

// number of sections for the view 
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 
    return 1; 
} 

// numbers of items in section 
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 
    return 1; 
} 

// cell to return (uses the custom identifier of the cell in the storyboard) 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"quickNoteCell" forIndexPath:indexPath]; 
    return cell; 
} 

我也确信在故事板的小区标识符使用quickNoteCell,并改变了它的默认颜色为蓝色,但是我是ST没有看到细胞有任何想法吗?

回答

1

像周杰伦说,放线这里你@interface下,它应该工作。您发布的代码没有任何问题。

<UICollectionViewDelegate, UICollectionViewDataSource> 
0

你有没有实现的UICollectionViewDelegate和UICollectionViewDataSource协议?

是的CollectionView:cellForItemAtIndexPath:被称为?

+0

我还没有添加任何代码给委托协议,我的印象是,如果单元格安装在故事板中并且其中有物品(即, UIButton),他们应该直接渲染而无需处理任何代码,我今晚会查看委托协议并发布我的结果,感谢您的反馈。 – SmokersCough

+0

在我的原始文章中添加了对我的代码的更改,我不确定为什么单元格不显示。 – SmokersCough

9

你没有看到任何细胞,因为你已经产生了UICollectionViewController子类,其中添加了以下行viewDidLoad:。根据我的理解,这会产生空白单元格,当使用自动布局时,它们会被压缩到0,0大小。

删除这条线,看是否使用自定义collectionViewItems您在故事板定义无形UICollectionViewCells

// Register cell classes 
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; 
0

,而不是细胞,要加载从笔尖文件数据寄存器第一笔尖的CollectionView:

let nib = UINib(nibName: reuseIdentifier, bundle: Bundle.main); 
self.collectionView?.register(nib, forCellWithReuseIdentifier: reuseIdentifier); 

和收集鉴于委托只要致电:

collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)