gpt4 book ai didi

uicollectionviewcell - UICollectionView 单元格不可见

转载 作者:行者123 更新时间:2023-12-04 22:33:51 26 4
gpt4 key购买 nike

我最近在我的 Storyboard中添加了一个 UICollectionView,它当前被另一个 View 插入 View ,这似乎工作正常但是,使用 Storyboard编辑器我将 View 设置为包含 35 个在编辑器中看起来很好的单元格,但是当我运行应用单元格是不可见的。一些单元格内部有 UIButtons,这些也不会呈现。

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

任何帮助,将不胜感激。

谢谢

编辑 - -

好的,我已经在我的第二个 View Controller 中实现了适当的委托(delegate)方法,然后推送一个 segue 以调出 collectionview Controller ,我还添加到我的第二个 View Controller 头文件中,并将以下代码添加到 .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;
}

我还确保 Storyboard上单元格中的标识符使用 quickNoteCell,并将其默认颜色更改为蓝色,但是我仍然没有看到单元格有任何想法?

最佳答案

您没有看到任何单元格,因为您生成了一个 UICollectionViewController 子类,它在 viewDidLoad: 中添加了以下行.据我了解,这会产生空白单元格,在使用自动布局时会压缩到 0,0 大小。

删除此行以查看您在 Storyboard 中定义的单元格,而不是不可见的 UICollectionViewCells

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

关于uicollectionviewcell - UICollectionView 单元格不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13254891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com