标签: uicollectionviewcell

UICollectionView cellForItemAtIndexPath为nil

我有一个更新现有UICollectionView的函数.创建了UICollectionView,我可以看到它,但是当我想访问它的单元格来更新它时,它们是零.

-(void)finishExam{

    for (int i = 0; i < [self.questionsOverviewCollection numberOfItemsInSection:0]; i++) {

        NSLog(@"self.questionsOverviewCollection - %@",self.questionsOverviewCollection);
        NSLog(@"cell - %@",[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]);
        NSLog(@"overviewCell - %@",(OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]);
        NSLog(@"numOfCells - %d", [self.questionsOverviewCollection numberOfItemsInSection:0]);

        OverviewCell *cell = (OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
            [cell finishExam];
    }
}


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

    OverviewCell *cell = (OverviewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    [cell someSetUp];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

日志:

self.questionsOverviewCollection - <UICollectionView: 0xa1abc00; frame = (14 219; 217 441); clipsToBounds = YES; opaque = NO; autoresize = …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewcell

27
推荐指数
2
解决办法
2万
查看次数

如何自定义UICollectionViewCell子类的选择状态?

我有一个自定义的UICollectionViewCell子类,它覆盖initWithFrame:layoutSubviews设置其视图.但是,我现在正在尝试做两件我遇到麻烦的事情.

1)我正在尝试自定义UICollectionViewCell选择的状态.例如,我想改变图像的一个在UIImageViewUICollectionViewCell.

2)I要动画(光反弹)的UIImageUICollectionViewCell.

谁能指出我正确的方向?

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    MyCollectionViewCell *cell = (MyCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    [cell setSelected:YES];
}
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios uicollectionview uicollectionviewcell

26
推荐指数
3
解决办法
3万
查看次数

如何在UICollectionView中的UICollectionViewCells之间添加视图?

我正在尝试UIView在我UICollectionViewCell的s之间添加s UICollectionView而我不知道如何做到这一点.我正在努力完成这样的事情:

截图

我可能需要写一个自定义UICollectionViewLayout,但我真的不知道从哪里开始.

iphone objective-c ios uicollectionview uicollectionviewcell

24
推荐指数
1
解决办法
1万
查看次数

UICollectionview中的不同单元格大小

在我的iPhone应用程序中,我在集合视图上显示图像.我从网址获取图片,网址也是我获得的图片大小.例如: - 假设有两种图像横向和纵向.我得到肖像图像的值P和横向图像的L值

如何自定义collectionView单元格的大小?

iphone ios uicollectionview uicollectionviewcell

24
推荐指数
2
解决办法
4万
查看次数

尝试在UICollectionViewCell Swift中覆盖"selected"以获取自定义选择状态

我正在尝试在UICollectionView中为我的单元格实现自定义选择样式.尽管可以在didSelect和didDeSelect方法中手动执行此操作,但我希望通过操作UICollectionViewCell中的"selected"变量来实现此目的.

我有这个代码:

    override var selected: Bool {
    get {
        return super.selected
    }
    set {
        if newValue {
            self.imageView.alpha = 0.5
            println("selected")
        } else if newValue == false {
            self.imageView.alpha = 1.0
            println("deselected")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我选择一个单元格时,单元格会突出显示但"选中"会被打印两次并且取消选择不起作用(即使实现了两个UICollectionView方法).

我该怎么做?谢谢!

ios uicollectionview uicollectionviewcell swift

24
推荐指数
3
解决办法
2万
查看次数

获取按钮操作:UICollectionView Cell

我创建了一个UICollectionViewCell由笔尖和里面添加一个按钮,并创建了一个h和.m文件添加类的碎粒file's owner.然后在.M写了一个按钮动作经由出口连接它.

集合视图填充正常,但无法触发按钮操作.我认为收集单元的代表被调用.

我怎样才能获得按钮动作?

ipad ios uicollectionview uicollectionviewcell

23
推荐指数
3
解决办法
3万
查看次数

UICollectionView动画(插入/删除项目)

我想在插入和/或删除UICollectionViewCell时自定义动画样式.

我需要这个的原因是默认情况下我看到插入一个单元格的动画平滑淡入淡出,但是删除一个单元格有一个向左移动+淡出动画的组合.如果不是一个问题,我会很高兴.

删除一个单元格后,当我添加一个单元格时,它仍会重复使用,当它重新使用时,它不会添加默认的淡入淡出效果,而是它是向左移动+淡入的组合.

我不确定为什么我在动画中遇到这种不一致.如果这是一个已知的错误/问题/愚蠢(在我这边:) :)请让我知道如何解决它.

否则,让我知道如何在删除单元格时设置自定义动画(或指向我的教程).

谢谢

UPDATE

通过继承UICollectionViewFlowLayout并添加此行代码来修复奇怪的动画行为

- (UICollectionViewLayoutAttributes *) initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath {

      return nil;
}
Run Code Online (Sandbox Code Playgroud)

而已!:)

iphone objective-c ios uicollectionview uicollectionviewcell

23
推荐指数
2
解决办法
4万
查看次数

使用reloadData方法重新加载UICollectionView会在重新加载数据之前立即返回

我需要知道何时重新加载UICollectionView已经完成以便以后配置单元格(因为我不是单元格的数据源 - 其他明智的就是已经完成它...)

我试过像这样的代码

[self.collectionView reloadData];
[self configure cells]; // BOOM! cells are nil
Run Code Online (Sandbox Code Playgroud)

我也试过用

[self.collectionView performBatchUpdates:^{
  [self.collectionView reloadData];
    } completion:^(BOOL finished) {
        // notify that completed and do the configuration now
  }];
Run Code Online (Sandbox Code Playgroud)

但是当我重新加载数据时,我正在崩溃.

如何将数据重新加载到集合中,并且只有在完成重新加载后才能重新加载 - 执行特定的完成处理程序

objective-c-blocks completionhandler uicollectionview uicollectionviewcell

23
推荐指数
3
解决办法
3万
查看次数

自定义UICollectionViewCell中的UIImageView始终返回nil

好吧,在我的故事板上我已经用3个单元格创建了一个UICollectionView.我为其制作了一个自定义类的单元格之一显然扩展了UICollectionViewCell:

在此输入图像描述

我在ViewDiDApear中注册了这个类:

[self.collectionView registerClass:[DeviceImageCell class] forCellWithReuseIdentifier:@"Cell1"];
Run Code Online (Sandbox Code Playgroud)

此外,我已将imageView添加到该特定单元格,并在我的自定义类中添加了该imageView的插座.当我制作自定义单元格时会出现问题,它会忘记我的故事板中设置的所有内容,即背景颜色,我的图像视图所在的位置等等.因此,我的imageView始终返回nil.

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

    if(indexPath.row == 0)
    {
        static NSString *identifier = @"Cell1";
        DeviceImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        UIImage *image = [UIImage imageNamed:@"dysart-woods-full.jpg"];
        cell.imageview.image = image;
        cell.backgroundColor = [UIColor blueColor];

        //cell.imageview.image = image;
        return cell;
    }
    else if(indexPath.row == 1)
    {
        static NSString *identifier = @"Cell2";
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        return cell;
    }
    else
    {
        static NSString *identifier = @"Cell3";
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        UIImageView *imageView …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionviewcell

23
推荐指数
2
解决办法
8215
查看次数

如何在Swift中将UILongPressGestureRecognizer与UICollectionViewCell一起使用?

我想弄清楚当我长按单元格时如何打印UICollectionViewCell的indexPath.

我怎么能在Swift中做到这一点?

我已经到处寻找一个如何做到这一点的例子; 在斯威夫特找不到一个.

uigesturerecognizer ios uicollectionviewcell swift

22
推荐指数
3
解决办法
3万
查看次数