Iphone 带两个控制器的UI分段控制
您好,我正在制作一个带有两段的UISegmentedControl。单击“段”选项卡中的任何一个都会显示一个控制器,其中包含一个表视图。到目前为止,我可以完成一些事情,但当我在表格中选择一个单元格时,我想推一个新的viewcontroller,我可以看到这一点Iphone 带两个控制器的UI分段控制,iphone,uisegmentedcontrol,Iphone,Uisegmentedcontrol,您好,我正在制作一个带有两段的UISegmentedControl。单击“段”选项卡中的任何一个都会显示一个控制器,其中包含一个表视图。到目前为止,我可以完成一些事情,但当我在表格中选择一个单元格时,我想推一个新的viewcontroller,我可以看到这一点 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 被调用,它也运行所有的代码,但我看不到新的视图 基
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
被调用,它也运行所有的代码,但我看不到新的视图
基本上,问题在于私有视图和公共视图无法访问任何导航属性
这是我想做的屏幕截图
这是密码
AppDelegate
UINavigationController *localNavigationController;
ManageSegmentedViewControl *manageSegmentedViewControl = [[ManageSegmentedViewControl alloc]init]];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:pickUpDootController];
localNavigationController.navigationBar.barStyle = UIBarStyleBlack;
ManagedSegmentedViewControl
- (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];
}
}
my privateviewcontroller和publicviewcontroller是如何成为navigationcontroller的一部分并访问navigationcontroller的所有属性的听起来好像您想在分段控件更改时推送一个新的视图控制器,对吗?但是我不知道这与选择表格单元格有什么关系。不,我不想推送,我有两个视图控制器,当你选择一个分段控件时会显示,我的两个视图控制器都有一个表格视图,所以当你点击单元格时,我想在堆栈上推送一个新的视图控制器,这就是我找不到的方法。听起来你想在分段控件更改时推一个新的视图控制器,对吗?但是我不知道这与选择表格单元格有什么关系。不,我不想推送,我有两个视图控制器,当你选择一个分段控件时会显示,我的两个视图控制器都有一个表格视图,所以当你点击单元格时,我想在堆栈上推送一个新的视图控制器,这就是我找不到的方法。