2014-06-19 3 views
0

이것은 매우 이상한 문제입니다. iPad 또는 iPad 시뮬레이터에서 완벽하게 실행되는 것처럼 보이지만 iPhone 또는 iPhone 시뮬레이터에서 실행할 때 문제가있는 UICollectionView가 있습니다. 문제는 항목이 데이터 소스에 추가되고 reloadData를 수행하면 새로 추가 된 항목이 컬렉션보기에 표시되지 않는다는 것입니다. 보기 컨트롤러를 모두 종료했다가 다시 열면 해당 항목이 나타납니다. 이 문제는 완벽하게 작동하는 iPad가 아니라 iPhone에서만 발생합니다.ios7.1.1 UICollectionView가 올바르게 다시로드되지 않음

모든 경우에 반환되는 항목의 개수가 정확하고 대기열 제거 루프 통과 횟수가 정확합니다 (디버거를 통해 확인 됨).

아래 관련 코드. 나는 다음과 viewDidAppear의 CV를 초기화 : 디버거를 실행

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

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

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 
    [cell.contentView.subviews makeObjectsPerformSelector: @selector(removeFromSuperview)]; 
    Item *item = (Item *) [cvData objectAtIndex:indexPath.row]; 
    CGFloat cellSize = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) ? 100.0f : 160.0f; 
    ImageWithAttachedLabel *imageWithLabel = [[ImageWithAttachedLabel alloc] initWithFrame:CGRectMake(0,0,cellSize,cellSize) 
                       withImage: [UIImage imageWithData: item.itemPhoto] 
                       withLabel: item.itemName 
                      roundBottoms: YES]; 

    [cell.contentView addSubview:imageWithLabel]; 
    return cell; 
} 

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section 
{ 
    return 3.0f; 
} 

numberOfItemsInSection이 항목의 정확한 수와 패스의 수를 반환 것을 발견 다음과 같이

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; 
    flowLayout.minimumInteritemSpacing = 3.0f; 
    UICollectionViewCell *cvCell = [[UICollectionViewCell alloc] init]; 
    cv = [[UICollectionView alloc] initWithFrame:CGRectMake(1.0f, 80.0f, [Utility screenWidth]-2.0f, [Utility screenHeight]-60.0f) collectionViewLayout:flowLayout]; 
    [cv setDelegate:self]; 
    [cv setDataSource:self]; 
    [cv setAllowsMultipleSelection:NO]; 
    [cv setAllowsSelection:NO]; 
    [cv setBackgroundColor: [UIColor whiteColor]]; 
    [cv registerClass:[cvCell class] forCellWithReuseIdentifier:@"Cell"]; 
    [self.view addSubview:cv]; 
    [self.view sendSubviewToBack:cv]; 
    [self queryData]; // [self queryData] also does a [cv reloadData] 

이력서 대표는 dequeue 루프는 정확하지만 마지막으로 추가 된 항목 (항목이 정렬되지 않았으므로 항상 cv의 마지막 셀이어야 함)은 표시되지 않습니다.

나는 꽤 비슷한 것을 언급하는 기사를 찾을 수 없었으므로 나는 어딘가에 버그가 있다고 짐작하고있다. 그러나 그것은 애매하다.

의견을 보내 주시면 감사하겠습니다. 당신이 당신의 데이터 소스에 새 항목을 추가 한 후

답변

0

은 아마 당신은이 작업을 수행하여 표시 할 새로 추가 된 항목을 강제 할 수

int size = [cvData count]; 
NSIndexPath *lastCell = [NSIndexPath indexPathForRow:size inSection:0]; 
[self.collectionView insertItemsAtIndexPaths:@[lastCell]]; 

(당신이 당신의 이력서에 self.collectionView 포인트 가정)

관련 문제