Smo*_*ugh 4 uicollectionviewcell
我最近在我的故事板中添加了一个UICollectionView,它目前被另一个视图推入视图,这似乎工作正常但是,使用故事板编辑器我设置视图包含35个单元格,在编辑器中看起来很好,但是当我运行应用程序细胞是不可见的.一些单元格内部有UIButton,这些单元格也不呈现.
要仔细检查视图是否渲染我在编辑器中更改了背景颜色并再次运行,颜色正确更新.我是否正确地假设设置应该自动呈现单元格而不必在编辑器中设置任何委托代码?
任何帮助,将不胜感激.
谢谢
编辑 - -
好吧,我已经在我的第二个视图控制器中实现了相应的委托方法,然后推送segue以显示集合视图控制器,我还添加到我的第二个视图控制器头文件并将以下代码添加到.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;
}
Run Code Online (Sandbox Code Playgroud)
我还确保故事板上单元格中的标识符使用quickNoteCell,并将其默认颜色更改为蓝色,但是我仍然没有看到该单元格的任何想法?
Ale*_*one 10
您没有看到任何单元格,因为您已生成一个UICollectionViewController子类,其中添加了以下行viewDidLoad:.根据我的理解,这会产生空白单元格,在使用autolayout时会被压缩到0,0.
删除此行以查看您在故事板中定义的单元格而不是不可见的UICollectionViewCells
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
Run Code Online (Sandbox Code Playgroud)
就像 Jay 说的,将这行代码放在你的 @interface 下,它应该可以工作。您发布的代码没有任何问题。
<UICollectionViewDelegate, UICollectionViewDataSource>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3461 次 |
| 最近记录: |