UITableView With Multiple Sections

后端 未结 6 1674
名媛妹妹
名媛妹妹 2020-12-04 19:36

I want to make tableView with multiple section but i do not want to use dictionary i have two arrays i want that first array should be loaded in first section and second in

6条回答
  •  抹茶落季
    2020-12-04 20:20

     - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
          return 2 ;
     }
    
     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
          if (section==0)
          {
                 return [array1 count];
          }
          else{
                 return [array2 count];
          }
     }
    
     - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
          if(section == 0)
               return @"Section 1";
          else
               return @"Section 2";
     }
    
    
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    
          static NSString *CellIdentifier = @"Cell";
    
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
         if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
          }
    
     if (indexPath.section==0) {
         ObjectData *theCellData = [array1 objectAtIndex:indexPath.row];
         NSString *cellValue =theCellData.category;
         cell.textLabel.text = cellValue;
     }
     else {
         ObjectData *theCellData = [array2 objectAtIndex:indexPath.row];
         NSString *cellValue =theCellData.category;
         cell.textLabel.text = cellValue;
     }
         return cell;        
     }
    

提交回复
热议问题