0

我有主视图控制器,它由几个按钮而不是 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];
}

有人可以建议更改吗?

4

1 回答 1

0

Well, you can do this by only one method.
First set tag to all the buttons and add reference of all the buttons to single method.

- (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.
}
于 2013-08-14T06:30:41.500 回答