UICollectionView 的 cellForItemAtIndexPath 没有被调用 [英] UICollectionView's cellForItemAtIndexPath is not being called

查看:26
本文介绍了UICollectionView 的 cellForItemAtIndexPath 没有被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这只是我第二次使用 UICollectionView,也许我已经咬得比我能咀嚼的多,但是:

Only my second time using UICollectionView's and perhaps I have bitten off more than I can chew but nevertheless:

我正在实现一个 UICollectionView (myCollectionView),它使用我已经子类化的自定义 UICollectionViewCell.子类单元格 (FullReceiptCell) 包含 UITableView,并且是 viewcontroller 的大小.我正在尝试允许在 FullReceiptCells 之间进行水平滚动.

I am implementing a UICollectionView (myCollectionView) that uses custom UICollectionViewCell's that I have subclassed. The subclassed cells (FullReceiptCell) contain UITableView's and are the size of the viewcontroller. I am trying to allow for horizontal scrolling between the FullReceiptCells.

包含 myCollectionView 的子类 UICollectionViewController 被推送到导航控制器堆栈.目前,myCollectionView loas 和水平滚动已启用.但是,看不到任何单元格.我已经确认了

The subclassed UICollectionViewController that contains myCollectionView is being pushed on to a nav controller stack. Currently, myCollectionView loas and horizontal scrolling is enabled. However, no cells are visible. I have confirmed that

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

已运行并返回大于 0 的整数.我还确认 myCollectionView 的委托和数据源已在 IB 中正确设置为子类 UICollectionViewController.

has run and is returning an integer greater than 0. I have also confirmed that myCollectionView's delegate and datasource are properly set in IB to the subclassed UICollectionViewController.

要加载单元格的方法:

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

没有被调用.

这是我在该控制器中推送 UICollectionViewController 和 viewDidLoad 方法的地方(注意:initWithBill 是普通初始化程序的替代):

Here is where I push the UICollectionViewController and my viewDidLoad method within that controller (NOTE: initWithBill is an override of the normal initializer):

在之前的 ViewControllers .m 文件中:

In the prior ViewControllers .m file:

FullReceiptViewController *test = [[FullReceiptViewController alloc] initWithBill:currentBill];
test.title = @"Review";
[self.navigationController pushViewController:test animated:YES];

在 FullReceiptViewController.m 中:

In FullReceiptViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.myCollectionView registerClass:[FullReceiptCell class] forCellWithReuseIdentifier:@"FullReceiptCellIdentifier"];
    self.myCollectionView.pagingEnabled = YES;
    // Setup flowlayout

    self.myCollectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    [self.myCollectionViewFlowLayout setItemSize:CGSizeMake(320, 548)];
    [self.myCollectionViewFlowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    [self.myCollectionViewFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    self.myCollectionViewFlowLayout.minimumLineSpacing = 0;
    self.myCollectionViewFlowLayout.minimumInteritemSpacing = 0;
    [self.myCollectionView setCollectionViewLayout:myCollectionViewFlowLayout];
    //testing to see if the collection view is loading
    self.myCollectionView.backgroundColor = [UIColor colorWithWhite:0.25f alpha:1.0f];

关于为什么它没有被调用的任何线索?

Any clue as to why it is not being called?

推荐答案

就我而言,这是因为我的布局类错误地从 UICollectionViewLayout 而不是 UICollectionViewFlowLayout

In my case, it was because my layout class incorrectly subclassed from UICollectionViewLayout instead of UICollectionViewFlowLayout

这篇关于UICollectionView 的 cellForItemAtIndexPath 没有被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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