2013-09-24 49 views
1

我有一個UIViewController它可以對didSelectItemAtIndexPath調用UICollectionView#reloadData在UICollectionViewDelegate#的CollectionView:didSelectItemAtIndexPath:隱藏所有細胞

@interface 

id section1Item 
NSMutableArray *section2Items 
NSMutableArray *section3Items 

@end 

@implementation 

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

    if (indexPath.section == 0) { 

     ; 

    } else if (indexPath.section == 1) { 

     self.section1Item = [self.section2Items objectAtIndex:indexPath.row]; 

    } else { // indexPath.section == 2 

     id newSection2Item = [self.section3Items objectAtIndex:indexPath.row]; 

     [self.section2Items addObject:newSection2Item]; 

     [self.section3Items removeObject:newSection2Item]; 

    } 


    [collectionView reloadData]; 

} 

@end 

的代碼背後的想法是,我的CollectionView具有的靜態數以下實施部分,並在第3部分的項目上粘貼將項目移動到部分2,並在第2部分的項目上點擊使其成爲第1部分中的項目。

但是,一旦我對dataStructure(section1Item,section2Items和section3Items),並調用reloadData,我所有的UICollect ionView單元消失。這個問題的一些症狀

  1. 在reloadData調用後,我的dataSource方法的非調用。我試着在我的numberOfSectionsInCollectionView和collectionView:numberOfItemsInSection的實現中放置一個斷點,但它們沒有被擊中。
  2. 我試着用RevealApp調試,我發現reloadData調用後,我所有的UICollectionViewCell的了隱藏屬性設置爲「是」,即使我沒有任何代碼在我的代碼庫調用.hidden = YES;
  3. 我也試着重寫UICollectionViewCell#setHidden來檢測一下(如果有的話)UIKit框架的一部分調用它,又沒有斷點觸發器。

工具細節:我正在iOS7模擬器上使用XCode5-DP6。

更新:我的UICollectionView在第一次渲染時顯示所有單元格。

+0

我supect如果沒有被調用的所有數據源的方法意味着你的CollectionView本身是零莫名其妙。 – bhawesh

+0

@BKC我更新了我的問題,但collectionView不是零,因爲我的初始渲染正確。 –

+0

有一個解決方案張貼在另一個線程中爲我工作 - http://stackoverflow.com/a/14804429 –

回答

0

好偷看,所以我能夠找出問題。代表(自我)是UIViewController的一個子類。在init中,我正在分配self.view = viewFromStoryBoard,其中viewFromStoryBoard由調用者傳入,並在故事板中設置。

因爲我沒有真正使用子類UIViewController提供的任何設施,所以我決定切換到子類NSObject並手動保留指向UICollectionView的指針。

這個固定我的問題。然而,我不是100%的問題的確切性質。我猜不知什麼原因,重寫UIViewController的視圖並不是全部。

0

有許多與iOS 7和UICollectionView錯誤的......在我的情況reloadData不能正常工作,其工作原理與延遲。

+0

你將不得不提供一些關於「無法正常工作」的更多細節,所以其他人可以幫助您。你有沒有嘗試在委託方法中放置一個斷點,看看它們是否在reloadData調用之後被擊中? –

+0

這不是一個真正的答案。你應該把它寫成評論。 – Nico