IOS: tableview delegate methods for two tableview

前端 未结 4 869
暗喜
暗喜 2020-12-31 20:28

I have these delegate method for a tableview inside a class:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)ta         


        
4条回答
  •  旧巷少年郎
    2020-12-31 21:25

    Yes you can do it with tag. Give your UITableViews the tags 1 and 2.

    set up an switch:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil){
        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewStylePlain reuseIdentifier:CellIdentifier] autorelease] ; 
    }
    
    switch ([tableView tag]) {
      case 1:{
        [[cell textLabel] setText:@"First tag"]
        break;
      }
      case 2:{
        [[cell textLabel] setText:@"Second tag"]
        break;
      }
      default:
        break;
    }
    
    return cell;
    }
    

提交回复
热议问题