UICollectionView 单元格不可见 [英] UICollectionView cells are invisible

查看:37
本文介绍了UICollectionView 单元格不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在我的故事板中添加了一个 UICollectionView,它目前被另一个视图推入视图,这似乎工作正常,但是,使用故事板编辑器我将视图设置为包含 35 个单元格,这些单元格在编辑器中看起来不错,但是当我运行应用程序,细胞是不可见的.一些单元格内部有 UIButtons,但它们也不会呈现.

I recently added a UICollectionView to my storyboard, it's currently pushed into view by another view and this appears to be working fine however, using the storyboard editor i set the view to contain 35 cells which in the editor look fine, but when i run the app the cells are invisible. Some of the cells have UIButtons inside and these don't render either.

为了仔细检查正在渲染的视图,我在编辑器中更改了背景颜色并再次运行它,颜色更新正确.我是否认为设置应该自动呈现单元格而我不必运行任何委托代码(如果它们已在编辑器中设置)?

To double check the view was rendering i changed the background colour in the editor and ran it again, the colour updated correctly. Am i right in assuming that the setup should automatically render the cells without me having to run any delegate code if they have been setup in the editor?

任何帮助将不胜感激.

谢谢

编辑----

好的,我已经在我的第二个视图控制器中实现了适当的委托方法,然后推送一个 segue 以显示 collectionview 控制器,我还添加了我的第二个视图控制器头文件并将以下代码添加到 .M 文件:

Ok i have implemented the appropriate delegate methods in my second view controller that then pushes a segue to bring up the collectionview controller, i also added the to my second view controller header file and added the following code to the .M file:

// 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,并将其默认颜色更改为蓝色,但是我仍然没有看到单元格任何想法?

I have also made sure the identifier in the cell on the storyboard uses the quickNoteCell, and changed its default colour to blue, however i am still not seeing the cell any ideas?

推荐答案

就像 Jay 所说的,把这行放在你的 @interface 下,它应该可以工作.您发布的代码没有任何问题.

Like Jay said, put the line here under your @interface and it should work. Nothing is wrong in the code you posted.

<UICollectionViewDelegate, UICollectionViewDataSource>

这篇关于UICollectionView 单元格不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆