2013-05-16 42 views
1

如何在UICollectionView的不同部分顯示不同數目的單元格。請爲此提供任何示例。UICollectionView:不同部分中不同數目的單元格

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
for(int i=0; i<[arrSeatSel count]; i++) 
{ 
    int c; 
    NSString *cnt = [NSString stringWithFormat:@"%@",[arrSeatSel objectAtIndex:i]]; 
    c = [cnt intValue]; 
    return c; 
} 
return 1; 
} 

在此先感謝。

+0

可以顯示出什麼把你想要... –

+0

@ SAMIR RATHOD我希望每個部分都有不同數量的單元格,我有一個包含值爲3,6,5的數組,這些是每個單元格中的單元格數量需要。並且包含其中的項目的數組計數3意味着部分的數目是3.希望您明白我的觀點。 –

回答

0

完成這樣

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 
NSLog(@"vals count:%d", [arrSeats count]); 
for(int i=0; i<[arrLevels count]; i++) 
{ 
    if(section == i) 
    { 
     int c; 
     NSString *cnt = [NSString stringWithFormat:@"%@",[arrTot objectAtIndex:i]]; 
     c = [cnt intValue]; 
     return c; 
    } 
} 
return 1; 
} 
0

使用本UICollectionView數據源和委託方法

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 

     if (section==1) { 

      return [arrSearchCelebs count]; // your array count. 

     } 
     else if (section==2){ 
      return 2; 
     } 
     else { 
      return 5; 
     } 
    } 

是一樣的UITableView的委託和數據源的方法..

+0

讓我更新我的問題,它會使更具體。 –

+0

請立即檢查。 –

+0

好的,但在哪一部分你想添加更多的行。你沒有在你的編碼中指定你的部分。它返回C的所有部分。 –

相關問題