2013-02-28 11 views
5
से केवल पहला आइटम

दो संस्थाओं (- >>कर्मचारीविभाग <) कर रहे हैं।UICollectionView प्रदर्शित करता है डाटासेट

इस विभाग में 4 कर्मचारी हैं। जब मैं इस विभाग में सभी कर्मचारियों को लाता हूं तो मेरी लॉग विंडो शो:

कोरडाटा: एनोटेशन: कुल प्राप्त निष्पादन समय: 4 पंक्तियों के लिए 0.0017s।

सब कुछ ठीक है।

लेकिन UICollectionView 4 बार के लिए केवल पहला कर्मचारी प्रदर्शित करता है। उदाहरण के लिए:

Employee1, Employee1, Employee1, Employee1

बजाय

Employee1, Employee2, Employee3, Employee4

मैं बात cellForItemAtIndexPath में कुछ गलती है :

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cellRecipe";  
    collectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; 

    Employee *emp = [array_ objectAtIndex:indexPath.item]; 
    cell.name.text = emp.name; 
    cell.image.image = emp.thumbImg; 

    return cell; 
} 

array_ एक NSMutableArray लाने के बाद

उत्तर

4

समस्या अनुक्रमण विधि में है इस कोड की कोशिश है।

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView 
{ 
    return noOfItem/ noOfSection; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
    return noOfSection; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"cellRecipe";  
    collectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; 
    ; 

    Employee *emp = [array_ objectAtIndex:indexPath.section * noOfSection + indexPath.row]; 
    cell.name.text = emp.name; 
    cell.image.image = emp.thumbImg; 

    return cell; 
} 
+1

निर्धारित! गलती ** संख्या में थी IFItemsInSection ** और ** संख्याOfSectionsInCollectionView **) – Romowski