Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionview节/行/阵列_Ios_Objective C_Uicollectionview - Fatal编程技术网

Ios UICollectionview节/行/阵列

Ios UICollectionview节/行/阵列,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我想用UICollectionView做点什么。我希望它们以中间为中心,但为此我需要创建这样的东西: (Array consists of 5 items) X X <- 2 items in section 1 X X <- 2 items in section 2 X <- 1 item in section 3 谁能帮我在正确的单元格中显示正确的文本 亲切问候在cellForItemAtIndexPath: - (UICollectionViewCell *)col

我想用UICollectionView做点什么。我希望它们以中间为中心,但为此我需要创建这样的东西:

(Array consists of 5 items)
X X <- 2 items in section 1
X X <- 2 items in section 2
X   <- 1 item in section 3
谁能帮我在正确的单元格中显示正确的文本


亲切问候

cellForItemAtIndexPath:

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

    ....
    //since there is 2 items in each section
    int index = 2*indexPath.section + indexPath.row;
    [[cell detaildiceLabel] setText: [NSString stringWithFormat:@"%@", [[arrayDobbel objectAtIndex:index] returnRandomOptie]]];

    return cell;
}

您可以使用
部分
,并且
部分
未在您的
集合视图中使用:cellForItemAtIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    ....
    //since there is 2 items in each section
    int index = 2*indexPath.section + indexPath.row;
    [[cell detaildiceLabel] setText: [NSString stringWithFormat:@"%@", [[arrayDobbel objectAtIndex:index] returnRandomOptie]]];

    return cell;
}