• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 不为 collectionView 调用 cellForItemAtIndexPath

[复制链接]
菜鸟教程小白 发表于 2022-12-12 11:23:05 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在 Storyboard 中采用了 UICollectionView。我还设置了 datasourcedelegate。 下面的方法被调用

 - (NSInteger)collectionViewUICollectionView *)collectionView numberOfItemsInSectionNSInteger)section{
 return 4;
}

但是 - (UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath 没有被调用。

附上 UICollectionView 的属性截图。关于这个问题的任何想法? image 1

enter image description here

如果我隐藏导航栏,现在 collectionView 是可见的。在设置顶部约束 Myheader Collection View.top = Top Layout Guide.bottom + 64 认为它位于 Controller 顶部。并且我在完成方法 -- (UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath 后收到以下警告。

警告: 能够同时满足约束。 可能至少以下列表中的约束之一是您不想要的。 尝试这个: (1)查看每个约束并尝试找出您不期望的; (2) 找到添加了不需要的约束或约束的代码并修复它。 ( “<_UILayoutSupportConstraint:0x7fda80dcff20 V:[_UILayoutGuide:0x7fda830006f0(0)]>”, “<_UILayoutSupportConstraint:0x7fda80daca10 V:|-(0)-[_UILayoutGuide:0x7fda830006f0](名称:'|':UIView:0x7fda80efb580)>”, "", “” )

将尝试通过打破约束来恢复

在 UIViewAlertForUnsatisfiableConstraints 处创建一个符号断点,以在调试器中捕获它。 中列出的 UIView 的 UIConstraintBasedLayoutDebugging 类别中的方法也可能有帮助。



Best Answer-推荐答案


我认为你没有正确设置流出。

因此,它不会转到 - (UICollectionViewCell *)collectionViewUICollectionView *)collectionView cellForItemAtIndexPathNSIndexPath *)indexPath 方法。所以,设置断点并检查每一个流程布局方法。

流式布局方法的顺序调用,

viewdidload 中的第一个 customflowlayout 将被调用,//如果您已设置

 UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    float ratio = self.aCollectionView.frame.size.width/3;
    [flowLayout setItemSize:CGSizeMake(ratio, ratio)];
    [flowLayout setMinimumInteritemSpacing:0];
    [flowLayout setMinimumLineSpacing:0]; 

第二,在您的情况下,此方法也称为

- (NSInteger)collectionViewUICollectionView *)view numberOfItemsInSectionNSInteger)section

第三 - 你需要从这一行检查,//你是否设置正确

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    float width = collectionView.frame.size.width/3;//120
    float height = collectionView.frame.size.height/4;//120
    return CGSizeMake(width-17,height-14);
}

4、这个方法调用

- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(14.0, 14.0, 0.0, 14.0);
}

最后这里调用了cellforitem方法。所以,你的这个方法没有被调用,问题是在上面的方法中尝试设置断点并改变单元格大小和边缘昆虫等然后尝试,

5、如果以上设置正确,则调用下面的方法。

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

关于ios - 不为 collectionView 调用 cellForItemAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37161779/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap