1

我工作的一個項目,我想從「保存的照片」和專輯名爲「通過MyAlbum」讀取的圖像,並提供列出他們UICollectionView多個選擇這樣如何預上UICollectionView

選擇單元格http://screencast.com/t/Y8VCgrWbH

當用戶單擊顯示myAlbum專輯中的myAlbum圖像時,以及當用戶單擊圖庫中顯示的圖庫時,每當用戶單擊兩個按鈕之一時,都會顯示圖庫中的圖像,我重新加載UIcollectionView數據。我還將選定的圖像保存在可變數組中,並在未選中時刪除。我想與所選陣列來比較圖像,然後顯示在單元格

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

已經被選中時用戶導航兩個按鈕。

回答

0

嘗試保存要選擇單元格,然後調用該委託方法:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 

viewWillAppear將這個可能。如果您保存了數據,您應該能夠計算出需要選擇的索引。

0

首先,授權您的收藏觀的多重選擇:

self.collectionView.allowsMultipleSelection = YES; 

後,實現兩個委託方法:

#pragma mark – UICollectionViewDelegate 
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Update Cell Selection 
    [_selectedItems addObject:[_data objectAtIndex:indexPath.item]]; 
} 

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Update Cell Selection 
    [_selectedItems removeObject:[_data objectAtIndex:indexPath.item]]; 
} 

_data與您的所有對象的數組,_selectedItems是用於保存當前項目的NSMutableArray或不。

這裏修改您的電池方面:

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

最後,以獲取更多信息,您可以看看here