UITableView With Multiple Sections

后端 未结 6 1688
名媛妹妹
名媛妹妹 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

    You are on almost right track....

    Let us consider your two arrays are arrOne and arrTwo.....

        - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
          if(section == 0)
          return [arrOne count];
          else
          return [arrTwo count];
        }
    
        - (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 = [arrOne objectAtIndex:indexPath.row];
            NSString *cellValue =theCellData.category;
            NSLog(@"cellValue = %@",cellValue); //To see the value of string cellValue
            cell.textLabel.text = cellValue;
    
            return cell;
    
        }
    
        else {
            ObjectData *theCellData = [arrTwo objectAtIndex:indexPath.row];
            NSString *cellValue =theCellData.category;
            cell.textLabel.text = cellValue;
    
            return cell;        
        }
    }
    

提交回复
热议问题