Tag: uicollectionviewcell

在第一次加载时预先select/高亮显示UICollectionViewCell

我试图预先selectUICollectionView中的第一个对象/ UICollectionViewCell? 我努力了: self.dateCollectionView.allowsMultipleSelection=NO; [self.dateCollectionView selectItemAtIndexPath:0 animated:YES scrollPosition:UICollectionViewScrollPositionLeft]; [self collectionView:self.dateCollectionView didSelectItemAtIndexPath:0]; [self.dateCollectionView reloadData]; 在viewDidLoad 。 这里是我的UICollectionView方法; -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.titles.count; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; cell.backgroundColor= [UIColor clearColor]; UILabel * dateLabel = (UILabel *)[cell viewWithTag:1]; UILabel * subText = (UILabel *)[cell viewWithTag:2]; subText.text=self.titles[indexPath.row]; subText.adjustsFontSizeToFitWidth=YES; if (cell.selected) […]

Swift,以编程方式更改UICollectionViewCell和UILabel(在单元格内)的宽度

我已经设置了一个单元格(UICollectionViewCell)的宽度等于UICollectionView的宽度,我正在尝试与该单元格内包含的UILabel完全相同的事情。 我认为下面的代码正是我想要达到的目标。 所以我在这里读了一些问题,还有几个教程,但我仍然不知道我怎么能做到这一点。 在几个问题中,它是关于使用collectionViewLayout说法,但我真的在如何在我的代码中使用它挣扎。 有任何想法吗? 谢谢! func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = collectionView.dequeueReusableCellWithReuseIdentifier("myCell", forIndexPath: indexPath) as LocationViewCell cell.locationLabel.text = "Hello there!" // Set cell & label width to 100% let collectionViewWidth = self.collectionView.bounds.size.width cell.frame.size.width = collectionViewWidth // Works cell.locationLabel.frame.size.width = collectionViewWidth // Does NOT 更新1 所以我添加了以下内容: func collectionView(collectionView: UICollectionView, […]

在UICollectionViewCell中的UICollectionView

我有兴趣有一个collectionview作为一个集合视图单元格的一部分,但由于某种原因无法弄清楚如何做到这一点。 我将在哪里实施细胞collectionview的必要的方法?

根据UICollectionView中的图像dynamic更改单元大小

我在水平集合视图中显示从服务器接收的dynamic图像。 当我设置collectionview时,我设置了这个: -(void)setupCollectionView{ [self setupPageControlView]; self.screensCollectionView.delegate=self; self.screensCollectionView.dataSource=self; [self.screensCollectionView registerNib:[UINib nibWithNibName:@"FGAppScreensCollectionViewItemCell" bundle:nil] forCellWithReuseIdentifier:@"screenCell"]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; [flowLayout setMinimumInteritemSpacing:0.0f]; [flowLayout setMinimumLineSpacing:0.0f]; [flowLayout setItemSize:CGSizeMake(165, 255)]; //[self.screensCollectionView setPagingEnabled:YES]; [self.screensCollectionView setCollectionViewLayout:flowLayout]; } 对于cellForRowAtIndexPath我下载像这样的图像: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifier = @"screenCell"; FGAppScreensCollectionViewItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:[self.imageURLArray […]

具有dynamic高度的UICollectionView不在单元格之间获得相同的空间

我有这样的类似问题 我在运行时产生了高度的视图。这是我的代码 @interface CollectionViewController () { NSMutableArray *arrMain; } @property(nonatomic,strong) NSMutableArray *arrMain; @end @implementation CollectionViewController @synthesize arrMain, – (void)viewDidLoad { [super viewDidLoad]; [cView registerNib:[UINib nibWithNibName:@"CViewCell" bundle:nil] forCellWithReuseIdentifier:kCellID]; CViewFlowLayout *fl = [[CViewFlowLayout alloc] init]; self.cView.collectionViewLayout = fl; NSString *strJson = MY FUNCTION WHICH RETURNS JSON STRING; SBJSON *parser = [[SBJSON alloc] init]; self.arrMain = [[NSMutableArray alloc] […]

UICollectionView:不会在重复使用的项目上计算不同大小的项目

我有一个收集视图与我声明的不同项目大小 – (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { FeedItem *item = [_imagesLinkArray objectAtIndex:indexPath.row]; return CGSizeMake(250, 200*item.sizeFactor); } 当单元格在collectionView:cellForItemAtIndexPath:被重新使用时collectionView:cellForItemAtIndexPath:正在使用reuesed项目大小呈现项目,而不是在sizeForItemAtIndexPath:指定的sizeForItemAtIndexPath: 。 有任何想法吗?

UICollectionView的单元格在滚动后并不总是被刷新

我在Storyboard(iPad)中定义了一个包含UICollectionView的视图,在视图底部还有一个UIToolbar 。 在UICollectionView我添加了一个UICollectionViewCell (由一个iPadCellCollectionViewCell类实现),它包含另一个视图,即核心图( CPTGraphHostingView类)。 我有一个名为X的类实现了UICollectionViewDelegate和UICollectionViewDataSource 。 在类X中,我为我的视图(在ViewDidLoad )的每个单元格构buildCore-Plot Graph,并且具有以下代码将图链接到UICollectionViewCell的单元格 – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString* cellId = @"ChartCollectionId"; iPadCellCollectionViewCell* cell = [self.theCollectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath]; MyChart* chart = [_charts objectAtIndex:indexPath.row]; cell.hostingView.hostedGraph = chart.barChart; return cell; } 它工作正常,所有我的graphics正确显示在屏幕上。 当用户滚动视图时会发生问题,然后一个或多个单元格变为“空白”。 我真的不明白为什么。 我find了一种解决方法,而不是在界面生成器中的UICollectionViewCell中添加CPTGraphHostingView ,我自己构build它,并且之前的代码变为: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString* cellId = […]

如何获取位于UICollectionView中心的单元格的indexPath

我如何findindexPath中的cell的UICollectionView ? 我有水平滚动,只有一个大的cell是可见的(部分两侧其他cell也是可见的)。 我需要删除位于中心的cell (意味着 – 当前cell )而不用触摸它。 只需按“垃圾箱”button并确认删除。 但现在它只删除第一个cell 。 – (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { if (buttonIndex == actionSheet.destructiveButtonIndex) { initialPinchPoint = ???????? self.tappedCellPath = [self.collectionView indexPathForItemAtPoint:initialPinchPoint]; Technique *technique = [arrayOfTechnique objectAtIndex:self.tappedCellPath.row]; [self deleteData:[NSString stringWithFormat:@"DELETE FROM TECHNIQUES WHERE TECHNIQUENAME IS '%s'",[technique.techniquename UTF8String]]]; [arrayOfTechnique removeObjectAtIndex:self.tappedCellPath.row]; //[arrayOfTechnique removeObjectAtIndex:[custom_layout ]]; [self removeImage:technique.techniquename]; [self.collectionView performBatchUpdates:^{ [self.collectionView deleteItemsAtIndexPaths:[NSArrayarrayWithObject:self.tappedCellPath]]; } […]

在每行的uicollectionview中填入给定数量的单元格

我有一个集合视图,我想让我们说每行4个单元格。 我知道要完成这一切,我需要做的是将collectionview.frame.size.width除以4.这很容易。 但是,我不能弄清楚的是,如何考虑收集视图侧面的插入和单元之间的间隔。 我在集合视图的左侧和右侧有10个像素插入,以及单元之间有10个像素间隔。 我怎样才能计算所需的单元格宽度考虑到这10个PX插图?

UICollectionViewCell 4.4和5.5英寸的dynamic大小

我有UICollectionView与故事板中的单元格。 每个单元格的大小设置为145×145。 它们在iPhone 4 – 5s上看起来不错,但是iPhone 6和6+的尺寸并不成比例。 而不是手动为每个设备设置不同的单元大小,我怎样才能dynamic地做到这一点? 在这里看到的例子:iPhone 5S: http : //prntscr.com/55vy7q,iPhone 6: http : //prntscr.com/55vyy2