TableView with multiple prototype cells

前端 未结 3 1978
广开言路
广开言路 2021-02-01 07:47

I had a simple question regarding a table view with 3 different kinds of prototype cells. The first two occur just once while the third occurs 4 times. Now what I\'m confused ab

3条回答
  •  孤独总比滥情好
    2021-02-01 08:23

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
        if (cell.tag == 0) 
       {
        return array1.count;
       }
       else(cell.tag == 1)
       {
        return array2.count;
       }    
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
     static NSString *cellIdentifier;
    
     NSString *membershipType = [membershipTypeArray objectAtIndex:indexPath.row];
    
     if ([membershipType isEqualToString:@"silver"]||[membershipType isEqualToString:@"gold"])
     {
         cellIdentifier = @"cell";
     }
     else if ([membershipType isEqualToString:@"platinum"])
     {
         cellIdentifier = @"premiumCustomCell";
         cell.customCellImageView.image = [cellImageArray objectAtIndex:indexPath.row];
     }
    
     cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
     if (!cell) {
         cell = [[CustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
     }
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     cell.headingLabel.text = [titleArray objectAtIndex:indexPath.row]; 
    }
    

提交回复
热议问题