相关疑难解决方法(0)

在UICollectionView中以编程方式选择项目

我有一个UICollectionViewController:

- (NSInteger)collectionView:(UICollectionView *)collectionView 
     numberOfItemsInSection:(NSInteger)section {
    return [self.pageTastes count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView  
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath {
     CellTasteCollectionView *cell = 
       [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" 
                                                 forIndexPath:indexPath];
     Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];       
     [[cell imageView] setImage:taste.image];
     [cell setObjectId:taste.objectId];    
     return cell;
}
Run Code Online (Sandbox Code Playgroud)

有用.我有这个viewDidLoad,允许用户选择多个项目:

[self.collectionView setAllowsMultipleSelection:YES];
Run Code Online (Sandbox Code Playgroud)

我想什么都有,就是第一次的CollectionView负荷,某些项目编程选择的基础上,他们objectIdCellTasteCollectionView.

这是我如何做到这一点:

- (void)collectionView:(UICollectionView *)collectionView 
         didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    Taste *taste = [self.pageTastes objectAtIndex:indexPath.item];
    printf("%s\n", [taste.objectId UTF8String]);
}
Run Code Online (Sandbox Code Playgroud)

当用户点击项目时调用它 - 这不是我想要的:我希望在UICollectionView加载时自动选择项目.

我该怎么做呢?

objective-c ios uicollectionview

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

标签 统计

ios ×1

objective-c ×1

uicollectionview ×1