2016-08-11 45 views
0

我有3個列表根據一些條件在UITableView中顯示。根據條件在同一個UITableView中顯示不同的數據集合

我正在使用自定義tableview單元格來顯示它。所以如果數據是第一組數據,我必須在一行中顯示總共5個標籤;如果它是第二組,那麼我必須顯示2個標籤和第三組1的標籤,其排列方式會有所不同。

通過使用故事板,我可以顯示這種類型的數據嗎?

+0

不,你不能使用故事板。 –

回答

0

您可以使用TableView部分區分不同的數據集。您可以關閉該部分以爲每個數據集創建自定義信息。

#pragma mark - UITableView 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection (NSInteger)section { 
    NSInteger rows; 
    switch (section) { 
     case 0: 
      rows = firstSet.count; 
      break; 
     case 2: 
      rows = secondSet.count; 
      break; 
     default: 
      rows = 0; 
      break; 
    } 
    return rows; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [[UITableViewCell alloc] init]; 

    switch (indexPath.section) { 
     case 0: 
      //Custom cell for first section 
      cell = [self customFirstSectionCell]; 
      break; 
     case 2: 
      //Custom cell for second section 
      break; 
     default: 
      rows = 0; 
      break; 
    } 

    return cell; 
} 
相關問題