带有两个控制器的UISegmentedControl

时间:2011-07-28 15:23:03

标签: iphone uisegmentedcontrol

您好我正在制作一个带有两个段的UISegmentedControl。单击任一段选项卡应显示一个控制器,其中包含一个表视图。到目前为止,我能够完成任务,但是当我在表格中选择一个单元格时,我想推送一个新的viewcontroller,我可以看到

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

被调用,它也运行所有代码,但我没有看到新视图。

基本上问题是私有视图,公共视图无法访问任何导航属性。

以下是我想要做的事情的屏幕截图

Screen Shot

以下是代码

的AppDelegate

UINavigationController *localNavigationController;
ManageSegmentedViewControl *manageSegmentedViewControl = [[ManageSegmentedViewControl alloc]init]];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:pickUpDootController];
localNavigationController.navigationBar.barStyle = UIBarStyleBlack; 

ManageSegmentedViewControl

 - (void)viewDidLoad
{
    [super viewDidLoad];

    PrivateViewController * controller1 = [[PrivateViewController alloc] init];
    PublicViewController * controller2 = [[PublicViewController alloc] init];


    self.segmentedViewControllers = [NSArray arrayWithObjects:controller1, controller2, nil];
   [controller1 release];
   [controller2 release];


   self.segmentedControl =
    [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Private",  @"Public", nil]];
   self.segmentedControl.selectedSegmentIndex = 0;
   self.segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
   self.segmentedControl.frame = CGRectMake(0, 0, 320, 44);

   [self.segmentedControl addTarget:self action:@selector(didChangeSegmentControl:) forControlEvents:UIControlEventValueChanged];
   [self.view addSubview:self.segmentedControl];
   [self didChangeSegmentControl:self.segmentedControl]; // kick everything off
}

- (void)viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
     [self.activeViewController viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.activeViewController viewDidAppear:animated];
 }

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.activeViewController viewWillDisappear:animated];
 }

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self.activeViewController viewDidDisappear:animated];
 }

- (void)viewDidUnload{
       [super viewDidUnload];

 }


 #pragma mark -
 #pragma mark Segment control

 - (void)didChangeSegmentControl:(UISegmentedControl *)control {
       UIViewController* newCtl = [self.segmentedViewControllers objectAtIndex:control.selectedSegmentIndex];

       if(newCtl == activeViewController)
          return;
       if([activeViewController isViewLoaded]){
         [self.activeViewController viewWillDisappear:NO];
         [self.activeViewController.view removeFromSuperview];
         [self.activeViewController viewDidDisappear:NO];
       }
       if(newCtl != nil){
         activeViewController = newCtl;
         [self.activeViewController viewWillAppear:NO];
         [self.view addSubview:self.activeViewController.view];
         [self.activeViewController viewDidAppear:NO];

       }
}

我的privateviewcontroller和publicviewcontroller如何成为navigationcontroller的一部分并访问navigationcontroller的所有属性

0 个答案:

没有答案