2012-11-06 2 views
0

iOS의 이미지 갤러리를 다시 만들려고합니다. 내가 업데이트 할 이미지의 상세 화면에서 iPhone : UICollectionView의 Indexpath.row

내비게이션 바의 제목은 가시 객체의 현재 indexpath.row을 얻을 수있는 방법과 그 옆에이 있습니까

3 of 19 

을 좋아합니다 UICollectionView이 스크롤을 중지하고 '3/19'제목을 업데이트 할 때 이미지 제목을 업데이트하십시오.

답변

3

이 코드는 정상적으로 작동합니다. (UICollectionViewDelegate가 UIScrollViewDelegate로부터 상속 된 바와 같이)

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{ 
    BOPhotoCollectionViewCell* currentCell = ([[collectionView visibleCells]count] > 0) ? [[collectionView visibleCells] objectAtIndex:0] : nil; 
    if(cell != nil){ 
     _index = [collectionView indexPathForCell:currentCell].row; 
     [self updateTitle]; 
    } 
} 
3

UIScrollViewDelegate의 위임 방법 이하 구현.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ 
    NSInteger currentIndex = scrollView.contentOffset.x/scrollView.frame.size.width; 
    [self setTitle:[NSString stringWithFormat:@"%ld of %ld",(long)currentIndex + 1, (long)self.itemList.count]]; 
} 
관련 문제