Tag: uicollectionview

UIACollectionView单元vs visibleCells

我正在尝试在xcode 4.5中使用自动化编写一个testing脚本。 我有一个UICollectionView ,我想点击一些目前不可见的单元格。 根据文档 ,我应该期望cells返回集合视图中的所有单元格,而visibleCells只返回当前可见的单元格。 相反,我所看到的是单元格只返回当前可见的单元格,并调用visibleCells停止脚本'undefined' is not a function (evaluating 'collection.visibleCells()') var target = UIATarget.localTarget(); var collection = target.frontMostApp().mainWindow().collectionViews()[0]; UIALogger.logMessage("Looking in collection: " + collection); UIALogger.logMessage("Cells: " + collection.cells() + " length " + collection.cells().length); UIALogger.logMessage("Visible cells: " + collection.visibleCells()); 上面的代码返回右边的UICollectionView ,第二个日志行打印: Cells: [object UIAElementArray] length 12 尽pipe我在集合视图中有100个项目,第三个日志行崩溃脚本。 这是一个文档/ UIACollectionView错误? 任何想法如何告诉自动滚动,直到它看到名为“我的单元格”的单元格? 我试过使用someCell.scrollToVisible ,但我需要有单元格来做到这一点,我没有,因为我不能从单元格中获取它。 […]

XCode 6 UICollectionview viewwithtag不起作用

似乎XCode 6是不同的使用viewwithtags然后XCode 5是。 我在故事板中使用XCode 6中的以下代码。 50个单元格被创build,但标签是不可见的。一切正如像标签设置等。如果我使用“旧”XCode 5的方式来做与寄存器单元格分类似乎适用于iOS 7,但在iOS 8的数据没有传递给标签,直到我开始滚动。 static NSString * const reuseIdentifier = @"MyCell"; – (void)viewDidLoad { [super viewDidLoad]; // Register cell classes [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier]; } – (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return 50; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = […]

在当前的应用程序添加UIPageViewController

我有一个应用程序在工作状态,其中我有三个屏幕1,2,3每个屏幕与UICollectionView关联,这是编程创build现在我想修改当前实现并将这些集合视图添加到UIPageViewControllers。 我试图用CollectionViewsfind许多与PageViewController有关的教程,但是无法find任何东西。 任何人都可以帮我实施这个或可以给我一个相关的参考。 我也提到了这个教程 ,但对我来说运气不佳:(

viewWithTag在初始化UICollectionViewCell时返回nil

刚开始使用UICollectionView 。 我用IB在UIViewController创build了一个简单的UICollectionView 。 它与分页水平滚动。 我在UICollectionView放置了一个简单的UICollectionView 。 我为单元格设置了重用标识符。 我在UICollectionViewCell放置了一个标签为100的UICollectionViewCell 。 在viewDidLoad ,我打电话给: [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Thing"]; 后来我尝试初始化单元格,如下所示: – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Thing" forIndexPath:indexPath]; cell.backgroundColor = [UIColor greenColor]; UILabel *nameLabel = (UILabel *)[cell viewWithTag:100]; nameLabel.text = @"Bogus"; return cell; } 当我运行应用程序,视图加载正确; 我可以水平滚动2个单元格。 我看到了识别每个细胞的难看的绿色。 但是, viewWithTag方法返回nil ,因此nameLabel文本未设置。 为什么? 请注意,我也尝试定义UICollectionViewCell的自定义子类,并调用registerClass。 在IB中,我将单元类更改为自定义子类,并将UILabel绑定到子类的UILabelsockets。 […]

在Swift中获取可见的IndexPath UICollectionView

如何在scrolling collectionView同时获取visible IndexPath ,我提到了很多link1 , link2,但是indexPathForCell不支持indexPathForCell 。

如何使一个collectionViewCell自动resize只有身高?

我使用了collectionView的stream式布局自动化function self.flow = [[UICollectionViewFlowLayout alloc] init]; self.flow.scrollDirection = UICollectionViewScrollDirectionVertical; self.flow.sectionInset = UIEdgeInsetsZero; self.flow.estimatedItemSize = CGSizeMake(320, 48); 我想要单元格将宽度的CollectionView(widthCell = widthCollectionView) 但我得到了整个大小的自动化工作。 我尝试玩内容压缩/拥抱优先 – 不起作用。 对于CollectionView的宽度等于320px,我得到了标签内容大小的单元格大小。 我的单元格看起来像 限制水平:H:| -8- [img(48)] – 8- [标签] -8- | 如何使autosize工作只​​为垂直而不是水平?

iOS:Storyboard CollectionView不会被触发

我有一个导航控制器内embedded的UICollectionView控制器。 collectionView列出项目,每个单元格应该延伸到ProjectDetail屏幕。 我根本无法得到继续触发。 如果我简单地在导航栏上放一个button,然后连接细节,它就可以工作。 但从我的CollectionView单元格触发不。 这里是故事板的样子: http : //cl.ly/RfcM我有一个从CollectionViewCell连接到ProjectDetailViewController 以下是我的ProjectDetailViewController中的相关代码: @interface ProjectCollectionViewController () { NSArray *feedPhotos; Projects *projects; } @end @implementation ProjectCollectionViewController – (void)viewDidLoad { [super viewDidLoad]; [self.collectionView registerClass:[FeedViewCell class] forCellWithReuseIdentifier:@"cell"]; [self loadData]; } – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"selected %d", indexPath.row); Project *project = [projects getProject:indexPath.row]; NSLog(@"project = %@", project); } – (void)loadData […]

如何删除所有项目并将新项目添加到UICollectionView?

在某些事件上, 我想删除一个uicollectionview中的所有单元格,并添加新的单元格(这将作为networking调用的结果填充) 我试着用deleteItemsAtIndexPaths。 reloadSections,deleteSections / insertSections。 他们每个人都撞我的应用程序。 以下是我的代码。 NSMutableArray* indexPathArray = [[NSMutableArray alloc] init]; for(int i=0; i < [self.jsonAlbumImageArray count]; ++i) { NSIndexPath* newPath = [NSIndexPath indexPathForRow:i inSection:0]; [indexPathArray addObject: newPath]; } [self.jsonAlbumImageArray removeAllObjects]; if(indexPathArray.count > 0 ) { [self.collectionView performBatchUpdates:^{ [self.collectionView deleteItemsAtIndexPaths:indexPathArray]; } completion: nil]; } // NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]; // […]

在UICollectionView布局中自定义头的位置会导致NSInternalInconsistencyException错误

我试图自定义UICollectionView使用子类UICollectionViewFlowLayout类(基于宽松的代码堆叠标题显示input链接描述在这里 )的标头的位置。 作为一个最小的testing,让我们说我只是想添加一个固定的偏移量到所有标题的位置: 我将所有的头添加到由layoutAttributesForElementsInRect返回的数组中,以便所有的头都被处理(这可能是问题的原因,我不确定) 然后,我通过在layoutAttributesForSupplementaryViewOfKind添加一个固定的偏移来更新每个头 完整的实现包括在这篇文章的末尾。 (顺便说一句,我知道添加所有标题,包括rect之外的所有标题,在第一步中并不是严格意义上的必要,但这是一个简单的例子,我想创build一个更复杂的定制,这将导致所有标题将被显示在绘制rect)。 但是,当我运行代码时,我得到以下NSInternalInconsistencyException : 2014-01-15 00:41:50.130 CollectionStackedHeaders[60777:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'layout attributes for supplementary item at index path (<NSIndexPath: 0x8a7db90> {length = 2, path = 0 – 0}) changed from <UICollectionViewLayoutAttributes: 0x8a7f8b0> index path: (<NSIndexPath: 0x8a7d9c0> {length = 2, path = 0 – 0}); […]

如何在UICollection补充视图中使用UIButton?

我试图在UICollectionView补充视图(页脚)中放置一个UIButton。 我已经将使用故事板的UIButton连接到UICollectionViewCell的子类,并可以通过编程方式更改其属性,包括背景图像。 但是,当我把button的内部事件连接到一个方法时,它不会触发。 事实上,该button甚至没有看起来对用户的触摸有视觉响应。 在解决问题时,我试图添加一个UIButton到集合视图的头部,并看到相同的行为。 将button添加到不相关的视图会在按下时产生交互效果。 在UICollection补充视图中,我需要做些什么来实现UIButton?