UICollectionView补充视图问题

时间:2014-04-01 10:26:19

标签: objective-c cocoa-touch uicollectionview

我在处理UICollectionView时遇到了以下问题。最后一个标题补充视图首先在viewForSupplementaryElementOfKind:中填充。这是该问题的一个例子

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"cell section %li",(long)indexPath.section);
    static NSString *cellIdentifier = @"MyCell";
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"header section %li",(long)indexPath.section);
    NSLog(@"%@",kind);
    static NSString *headerIdentifier = @"MyHeader";
    CollectionViewHeader *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier forIndexPath:indexPath];
    return header;
}

对于特定的dataSource模型,这会在控制台中生成以下输出

2014-04-02 12:30:50.195 fdasfsad[6353:60b] cell section 0
2014-04-02 12:30:50.200 fdasfsad[6353:60b] cell section 1
2014-04-02 12:30:50.203 fdasfsad[6353:60b] cell section 2
2014-04-02 12:30:50.205 fdasfsad[6353:60b] cell section 3
2014-04-02 12:30:50.207 fdasfsad[6353:60b] cell section 4
2014-04-02 12:30:50.209 fdasfsad[6353:60b] header 0
2014-04-02 12:30:50.210 fdasfsad[6353:60b] UICollectionElementKindSectionHeader
2014-04-02 12:30:50.212 fdasfsad[6353:60b] header 2
2014-04-02 12:30:50.214 fdasfsad[6353:60b] UICollectionElementKindSectionHeader
2014-04-02 12:30:50.216 fdasfsad[6353:60b] header 4
2014-04-02 12:30:50.218 fdasfsad[6353:60b] UICollectionElementKindSectionHeader
2014-04-02 12:30:50.219 fdasfsad[6353:60b] header 1
2014-04-02 12:30:50.221 fdasfsad[6353:60b] UICollectionElementKindSectionHeader
2014-04-02 12:30:50.223 fdasfsad[6353:60b] header 3
2014-04-02 12:30:50.224 fdasfsad[6353:60b] UICollectionElementKindSectionHeader

这是对的吗?在补充视图的情况下,最后一部分总是先填充?

更新:可能发现的错误

到目前为止,我在iPad Mini上测试应用程序。该项目设置为iPhone项目。当我在iPhone模拟器上测试应用程序时,我得到了预期的结果:

2014-04-02 12:35:35.251 fdasfsad[3276:60b] cell section 0
2014-04-02 12:35:35.253 fdasfsad[3276:60b] cell section 1
2014-04-02 12:35:35.254 fdasfsad[3276:60b] cell section 2
2014-04-02 12:35:35.254 fdasfsad[3276:60b] cell section 3
2014-04-02 12:35:35.255 fdasfsad[3276:60b] cell section 4
2014-04-02 12:35:35.255 fdasfsad[3276:60b] cell section 5
2014-04-02 12:35:35.256 fdasfsad[3276:60b] header 0
2014-04-02 12:35:35.256 fdasfsad[3276:60b] UICollectionElementKindSectionHeader
2014-04-02 12:35:35.256 fdasfsad[3276:60b] header 1
2014-04-02 12:35:35.257 fdasfsad[3276:60b] UICollectionElementKindSectionHeader
2014-04-02 12:35:35.257 fdasfsad[3276:60b] header 2
2014-04-02 12:35:35.257 fdasfsad[3276:60b] UICollectionElementKindSectionHeader
2014-04-02 12:35:35.258 fdasfsad[3276:60b] header 3
2014-04-02 12:35:35.258 fdasfsad[3276:60b] UICollectionElementKindSectionHeader
2014-04-02 12:35:35.259 fdasfsad[3276:60b] header 4
2014-04-02 12:35:35.259 fdasfsad[3276:60b] UICollectionElementKindSectionHeader
2014-04-02 12:35:35.259 fdasfsad[3276:60b] header 5
2014-04-02 12:35:35.260 fdasfsad[3276:60b] UICollectionElementKindSectionHeader

这可能是Xcode 5中的错误吗?

0 个答案:

没有答案