UISplitViewController在按钮单击主视图时按下多个详细信息视图

时间:2013-03-25 11:07:30

标签: ios ipad uisplitviewcontroller

我有主视图控制器,它由几个按钮而不是tableview组成。我想在不同的按钮点击时打开不同的详细信息视图。

我的代码如下所示,但这并未显示任何更改。

 - (IBAction)NewEntryBtn:(UIButton *)sender 
{

    NSLog(@"new entry btn");
    [self.appdelegate.splitViewController viewWillDisappear:YES];
    NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appdelegate.splitViewController.viewControllers objectAtIndex:1]viewControllers]];
    [viewControllerArray removeLastObject];

    self.secondVC=[[SecondDetailViewController alloc] init];
    [viewControllerArray addObject:self.secondVC];
    self.appdelegate.splitViewController.delegate = self.secondVC;

    [[self.appdelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];    


    [self.appdelegate.splitViewController viewWillAppear:YES];
}

- (IBAction)EditBtn:(UIButton *)sender 
{
   [self.appdelegate.splitViewController viewWillDisappear:YES];
    NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appdelegate.splitViewController.viewControllers objectAtIndex:1]viewControllers]];
    [viewControllerArray removeLastObject];

    self.secondVC=[[SecondDetailViewController alloc] init];
    [viewControllerArray addObject:self.secondVC];
    self.appdelegate.splitViewController.delegate = self.secondVC;

    [[self.appdelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];    


    [self.appdelegate.splitViewController viewWillAppear:YES];
}

有人可以建议改变吗?

1 个答案:

答案 0 :(得分:0)

嗯,你只能通过一种方法来做到这一点。
首先将tag设置为所有按钮,并将所有按钮的引用添加到单个方法中。

- (IBAction)btnClicked:(id)sender
{
    int btnNo = ((UIControl *) sender).tag;
    NSLog(@"Button Clicked - %d", btnNo);
    if (btnNo == 1)
     {
     // Navigate to first detail view controller
     }
    else if (btnNo == 2)
     {
     // Navigate to second detail view controller
     }
    .
    . 
    and so on.
}