代码之家  ›  专栏  ›  技术社区  ›  Oh Danny Boy

iPhone:两个uitableview;要切换的分段控件

  •  0
  • Oh Danny Boy  · 技术社区  · 14 年前

    我有一个包含两个视图的xib,每个视图都包含一个高度缩短的tableview。根视图有一个分段控制器,它应该切换视图。如何使每个tableview指向其相应的类?

    2 回复  |  直到 4 年前
        1
  •  1
  •   MyCSharpCorner    14 年前

    一种方法是从文件中向项目添加两个UITableViewController类->添加,然后单击Include Xib选项。这将创建两个表视图xib文件。然后,您可以在主控制器的ViewDidLoad事件中初始化这两个控制器,并为它们指定一个等于左&的帧;您的右视图如下:

    [firstTableController.view setFrame:rightView.frame];
    [secondTableController.view setFrame:leftView.frame];
    

    其中rightView和;leftView是UIView*对象,它连接到IB中的两个视图。

    然后可以使用主控制器中的addSubView将两个表控制器添加到主视图控制器:

    [self.view addSubView:firstTableController.view];
    [self.view addSubView:secondTableController.view];
    

    希望这有帮助。

        2
  •  0
  •   Abdul Yasin    11 年前
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    

    {

    int x;
    if (tableView.tag == 100)
    {
        x = [tab1 count];
    }
    
    
      if (tableView.tag == 101)
    
    
     {
        x = [tab2 count];
    }
    return x;
    
    }
    

    -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

    static NSString *cellIdentifier =  @"Helllo";
    
    
    UITableViewCell    *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil)
    {
    
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    
    
    
    
    
    if (tableView.tag ==100)
    {
        cell.textLabel.text= [tab1 objectAtIndex:indexPath.row]; 
    }
     if (tableView.tag == 101)
    {
         cell.textLabel.text=[tab2 objectAtIndex:indexPath.row]; 
    }
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    
    
    return cell;
    

    }

    tab1和tab2是数组。