Tag: uicollectionviewcell

插入新的单元格到UICollectionView

我试图添加一个新的单元格到我的集合视图,只有当它有多个项目已经在它。 我没有收集意见的工作太多,在文档和本网站的研究还没有帮助解决这个问题呢。 所以,在我的cellForItemAtIndexPath方法,我做了检查,看看它是否填充。 如果没有,我添加单元格,如下所示: – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { if (self.myArray.count != 0) { return self.myArray.count + 1; } else { return self.myArray.count; } } // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyNormalCollectionViewCellS *cells = (MyNormalCollectionViewCells *) [collectionView dequeueReusableCellWithReuseIdentifier:@"MyNormalCollectionViewCells” forIndexPath:indexPath]; cell.clipsToBounds […]

调整UICollectionViewCell以适应内容

我有一个标签被设置为调整其内容。 我想UICollectionViewCell做同样的事情。 无论如何,我无法实现这一点。 描述我目前的安排的照片可以在下面find:

无法从UICollectionViewCell实例访问Image

我正在跟随本教程对我的项目进行一些修改: http : //www.appcoda.com/ios-programming-uicollectionview-tutorial/ 我试图得到IB为我创build的UIImageView的实例。 这是我的IB的截图: 我有一个名为FeedViewCell的自定义类,它包含一个UIImageView。 这是cellForItemAtIndexPath代码: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; UIImageView *imageView = (UIImageView *)[cell viewWithTag:100]; imageView.image = [UIImage imageNamed:[postPhotos objectAtIndex:indexPath.row]]; return cell; } 问题是,UIImageView * imageView =(UIImageView *)[单元viewWithTag:100]; 返回为零。 使用viewWIthTag方法似乎对我来说是不可思议的,但在debugging器中,我看不到imageView是UICollectionViewCell的子视图。 如果你看看这个debugging屏幕,你可以看到单元格没有任何UIImageView子视图: 但是我看到2个UIImageViews作为CollectionView的子视图。 所以这似乎是我在IB做错了事。 这并不奇怪,因为我似乎总是与IB斗争(至less看代码我可以看到发生了什么)。 感谢您的任何build议! 更新:我放弃了使用IB挂钩ImageView,并尝试在代码中创build它,如下所示: http : //cl.ly/QFxs […]

如何创build水平dynamic的UICollectionView单元格? 迅速

嘿,我试图在视图控制器中使用集合视图单元格显示一组“标签”,但我很难find一种方法,使他们能够dynamicresize取决于string的长度。 现在单个单元格的大小是固定的,所以无论何时填充单元格的string超过单元格的大小,它都会进入第二行。 我想要这样的单元格可以改变长度取决于string的长度。 所以如果是“#Vegan”这个标签,它会自动resize,这样标签就不那么大了。 同样,如果它是像“#LaptopFriendly”这样的更长的string,它将变得水平更长,以容纳string,而不是使用第二行。 垂直长度可以保持不变。 谢谢! 更新(使用Rob代码遇到错误时的界面生成器设置): 模拟器截图:

UICollectionView启用取消选中单元格,同时禁用允许MultipleSelection

什么时候 collectionView.allowsMultipleSelection = YES; 我可以取消select的单元格。 什么时候 collectionView.allowsMultipleSelection = NO; 我无法取消选中的单元格。 无论如何,我只能设置 collectionView.allowsMultipleSelection = NO; 和 能否取消选定的单元格? 所以要么select一个,要么没有select。 我知道你可以实现你自己的select,然后在检测到手势时调用setSelected。 但我正在寻找一个更原生的解决scheme,你可以在uicollectionView自己configuration的东西。 谢谢!

Swift 3:如何水平居中在一个UICollectionView只有一节的最后一行单元格?

我只有一个部分使用UICollectionView 。 这是一些可视化: [ xxx ] [ xxx ] [ xx ] 如果UICollectionView中的最后一行没有填满所有3个单元格,我想将这些单元格居中,如下所示: [ xxx ] [ xxx ] [ xx ] 我试图从以下地方实施解决scheme: 如何水平居中UICollectionView单元? 如何居中alignmentUICollectionView的单元格? 但是,解决scheme移动所有的单元格,我只想移动最后一行,如果最后一行不包含X数量的单元格,因为我只有一个部分。 我知道如何设置插入,但我不知道如何做到这一点只是一个部分,并试图调整最后一排单元格的插图。 我刚开始使用UICollectionView ,不知道如何解决这个问题?

单元格中的单元格标签文本重叠

我正在尝试添加一个UILabel到我的collectionViewCell 。 但是,一些单元格文本开始与之前的单元格数据重叠之后。 更新 :这似乎只发生在我的手机(iphone 5),但不是在模拟器(2013年macbook空气)。 如这里所见: 我正在以编程方式实现整个视图。 这个问题似乎并没有与任何collectionview的元素,所以我会认为这个问题也适用于表视图。 我不确定我是否错过了以下几点: if(cell == nil) {// do something } 如果是这样的话,有人可以点亮一下这个function吗? 如果这不是问题,我真的不知道是什么原因造成的。 我也使用一个NSMutableAttributedString ,但是这不是问题,因为我试图插入一个普通的string,并得到相同的结果。 我的代码: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath]; TTSong *tempSong = [songArray objectAtIndex:indexPath.row]; UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 110, 150, 40)]; [cellLabel setTextColor:[UIColor whiteColor]]; [cellLabel setBackgroundColor:[UIColor colorWithRed:0.0 […]

iOS UICollectionView:单元格不显示

我错过了一些明显的东西,因为这不是一件困难的事情。 我有故事板(其他视图)中的集合视图,原型单元格的重用标识为“单元格”,并在该单元格中具有100标签的UILabel。 代码(样板): – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 4; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath]; UILabel *label = (UILabel *)[cell viewWithTag:100]; label.text = @"Hello"; return cell; } 该代码在UICollectionViewController ,因为它应该。 当我运行,视图出现,但没有单元格或文本可见。 cellForItemAtIndexPath中的一个NSLog确认它被调用了4次。 我甚至改变了原型单元格的背景颜色,显示甚至没有出现单元格。 在viewDidLoad ,它调用: [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; 我错过了什么?

collectionViewContentSize()与contentSize

有什么区别 collectionViewController.collectionViewLayout.collectionViewContentSize()和collectionViewController.collectionView.contentSize ? 你喜欢用什么?

如何在Scroll上设置UICollectionViewCell的大小,使其中间最大?

我有一个UICollectionView显示几行与一个全宽列(看起来像一个UITableView) 我想达到的是类似于这样的: …中间的细胞有更高的高度。 当用户向上和向下滚动时,中间单元格之前和之后的单元格animation回到给定单元格的默认高度。 有人可以概述我应该如何解决这个问题?