两个TableView在一个UITableViewController中

时间:2015-07-16 04:14:20

标签: ios iphone

我需要在一个UITableView中使用两个UITableViewController。我需要为每个UITableView创建两个自定义单元格。

我可以做到吗?请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个......在一个UIViewController中使用了两个UITableView ......

  -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView==self.tableview1)
    {
      return tableview1RowCount;
    }
    else if(tableView==self.tableview2)
    {
      return tableview2RowCount;
    }



}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (tableView==self.tableview1)
     {
          static NSString *CellIdentifier1 = @"tableview1_cell";

          tableview1_cell *cell1 = (tableview1_cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
         if (cell1 == nil)
         {
             NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"tableview1_cell" owner:self options:nil];
            cell1 = [nib objectAtIndex:0];
         }
         return cell1;
     }

     if (tableView==self.tableview2)
     {
          static NSString *CellIdentifier1 = @"tableview2_cell";

          tableview2_cell *cell2 = (tableview2_cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
         if (cell2 == nil)
         {
             NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"tableview2_cell" owner:self options:nil];
            cell2 = [nib objectAtIndex:0];
         }
         return cell2;
     }
}

和方法

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

与上面相同....用if条件分开tableviews,并为每个...提供动作......无论你想要什么...

相关问题