未调用UICollectionView的cellForItemAtIndexPath [英] UICollectionView's cellForItemAtIndexPath is not being called

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

问题描述

只有我第二次使用UICollectionView并且我可能咬过的东西比我可以咀嚼更多但是:

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

我正在实现一个使用自定义UICollectionViewCell的UICollectionView(myCollectionView)我已经分组了。子类化单元格(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?

推荐答案

对于那些后来偶然发现的人......原因是:

For those who stumble here later.... the reason:

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

没有被调用是因为collectionViewFlowLayout的高度太大了。

was not being called was because of the itemSize for the collectionViewFlowLayout's height was too big.

[self.myCollectionViewFlowLayout setItemSize:CGSizeMake(320, 548)];

如果我将高度更改为410,它将执行cellForItemAtIndexPath。

If I change the height to 410, it will execute cellForItemAtIndexPath.

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

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