2014-11-20 2 views
1

컬렉션보기를 사용하여 Excel보기를 만들었습니다. https://stackoverflow.com/questions/27036224/scrolling-disturbs-layout-of-collectionview 내가에 Shivam의 답변을보고 이후에 그 문제를 해결 : 나열된 콜렉션 뷰를 스크롤하는 동안에 앞서 나는이 문제에 직면했다가 올바른지 여부 모르겠어요 Collection View,with custom layouts, cells misbehave on scrolling가 큐 뷰를 다시로드 한 후에 셀을 가져올 수 없습니다.

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
    NSString *cellID = [NSString stringWithFormat:@"%@%d", @"cCell",indexPath.row]; 
    [myCollectionView registerClass: [CustomCell class] forCellWithReuseIdentifier:cellID]; 
    CustomCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath]; 

    [self configureCell:cell forIndexPath:indexPath]; 

    return cell; 
} 
-(void)configureCell:(CustomCell*)cell forIndexPath:(NSIndexPath*)indexPath{ 
// configuration code 
} 

, 그러나 그것의 작동.하지만 지금 나는 콜렉션 뷰의 재 장전과 관련된 또 다른 문제에 갇혀있다.

문제 ::: 나는 textFieldDidEndEditing 대리인을 구현 한 셀에 텍스트 필드가 있습니다. 나도 원하는 컬렉션보기에서 모든 셀에 프록시 탐색을 제공하는 다음 버튼을 제공했습니다. 다음 버튼의 클릭 된 메소드에서 currentIndexpath를 저장하고 콜렉션 뷰를 다시로드하고 저장된 인덱스 경로를 사용하여 다음 셀을 가져 와서 텍스트 필드를 가져 와서 첫 번째 응답자로 만듭니다. 그러나 다음 텍스트 필드는 첫 번째 응답자가되지 않습니다. 문제를 디버그하고 재로드 한 후 셀을 검색 할 수 없다는 것을 알았습니다. 재로드 라인을 제거하면 모든 것이 정상적으로 작동합니다.

NSIndexPath *reqIndexPath = [NSIndexPath indexPathForItem:colId inSection:currentSection]; 
CustomCell *cell = (CustomCell*)[self.collectionView cellForItemAtIndexPath:reqIndexPath]; 
+0

에 Lukewar 응답에

[self.collectionView reloadData]; [self.collectionView layoutIfNeeded]; 

덕분에 나는 http://stackoverflow.com/questions/18230918에 Lukewar의 솔루션을 본 후 문제를 해결/reloading-a-uicollectionview-using-reloaddata-method-returns-immediately-before 그냥 [self.collectionView layoutIfNeeded]를 추가했습니다. afterloadData – DRK

답변