2014-04-04 8 views
23

मेरे पास एक ऐसा फ़ंक्शन है जो मौजूदा UICollectionView को अपडेट करता है। UICollectionView बनाया गया है, मैं इसे देख सकता हूं, लेकिन जब मैं इसे अद्यतन करने के लिए अपनी कोशिकाओं तक पहुंच बनाना चाहता हूं, तो वे शून्य हैं।UICollectionView CellForItemAtIndexPath शून्य

-(void)finishExam{ 

    for (int i = 0; i < [self.questionsOverviewCollection numberOfItemsInSection:0]; i++) { 

     NSLog(@"self.questionsOverviewCollection - %@",self.questionsOverviewCollection); 
     NSLog(@"cell - %@",[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]); 
     NSLog(@"overviewCell - %@",(OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]); 
     NSLog(@"numOfCells - %d", [self.questionsOverviewCollection numberOfItemsInSection:0]); 

     OverviewCell *cell = (OverviewCell*)[self.questionsOverviewCollection cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; 
      [cell finishExam]; 
    } 
} 


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

    OverviewCell *cell = (OverviewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    [cell someSetUp]; 

    return cell; 
} 

प्रवेश करें:

self.questionsOverviewCollection - <UICollectionView: 0xa1abc00; frame = (14 219; 217 441); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0xe0617a0>; layer = <CALayer: 0xe0bbb00>; contentOffset: {0, 0}> collection view layout: <UICollectionViewFlowLayout: 0xe0cc3f0> 
cell - (null) 
overviewCell - (null) 
numOfCells - 30 
+0

आप सभी सेल अशक्त हो रही है या आप किसी सेल हो और उस के बाद यू अशक्त मिल सकता है? – CRDave

उत्तर

42
UICollectionView डॉक्स से

(मेरे अपने जोर)

वापसी मूल्य
इसी सूचकांक पथ पर सेल वस्तु या नहीं के बराबर है, तो सेल दिखाई नहीं दे रहा है या इंडेक्सपाथ सीमा से बाहर है।

आपको अपने अंतर्निहित मॉडल को अपडेट करना चाहिए, जो विचारों को डेटा प्रदान करता है।

+9

यह मेरे लिए काम किया, लेकिन [दृश्य reloadData] के साथ डेटा को पुन: लोड के अलावा, मैं भी http://stackoverflow.com/a/21480786/1388195 – zyzof

+19

कॉलिंग के अनुसार करने के लिए [दृश्य layoutIfNeeded] था [collectionView layoutIfNeeded] के लिए काम किया मुझे [संग्रह दृश्य reloadData] कॉल करने के बाद सेल प्राप्त करने के लिए। धन्यवाद @zyzof –

+3

सभी लेआउट के लिए धन्यवाद IfNeeded !!! : डी बस सोच रहा है, क्या किसी को पता है क्यों? मेरे मामले में कारण पूरे समय सेल दिखाई दे रहा है। – Happiehappie

6

इस प्रयास करें:

[collectionView reloadData]; 
[collectionView layoutIfNeeded];