Iphone UIToolbar和UINavigationController
我需要以模式显示视图。需要以模式显示的viewcontroller底部必须有一个UIToolbar。在此工具栏中有一个包含三个元素的uisegmentedcontroller。(想想tabbar) 在显示模态viewcontroller的viewcontroller中,我有:Iphone UIToolbar和UINavigationController,iphone,Iphone,我需要以模式显示视图。需要以模式显示的viewcontroller底部必须有一个UIToolbar。在此工具栏中有一个包含三个元素的uisegmentedcontroller。(想想tabbar) 在显示模态viewcontroller的viewcontroller中,我有: -(IBAction)presentModally:(id)sender { if (self.nvc == nil) { MyModalViewController *vc = [[MyModalViewC
-(IBAction)presentModally:(id)sender {
if (self.nvc == nil) {
MyModalViewController *vc = [[MyModalViewController alloc] init];
UINavigationController *navvc = [[UINavigationController alloc] initWithRootViewController:vc];
navvc.navigationItem.prompt = @"";
navvc.navigationBar.barStyle = UIBarStyleBlack;
[vc release];
self.nvc = navvc;
[navvc release];
}
[self presentModalViewController:self.nvc animated:YES];
}
MyModalViewController:
- (void)loadView {
[super loadView];
UIView *uiview = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 460.0f)];
uiview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view = uiview;
[uiview release];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 436.0f, 320.0f, 44.0f)];
toolbar.barStyle = UIBarStyleBlack;
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil];
UISegmentedControl *segCon = [[UISegmentedControl alloc] initWithItems:itemArray];
segCon.frame = CGRectMake(60, 4, 200, 36);
segCon.segmentedControlStyle = UISegmentedControlStyleBar;
segCon.tintColor = [UIColor darkGrayColor];
segCon.selectedSegmentIndex = 0;
[segCon addTarget:self action:@selector(changedSegment:) forControlEvents:UIControlEventValueChanged];
[toolbar addSubview:segCon];
self.segmentedControl = segCon;
[segCon release];
[[self navigationController].view addSubview:toolbar];
[toolbar release];
}
- (void)changedSegment:(id)sender {
UISegmentedControl *control = (UISegmentedControl *)sender;
int index = control.selectedSegmentIndex;
[[self navigationController] popViewControllerAnimated:NO];
[[self navigationController] pushViewController:[self.controllers objectAtIndex:index] animated:NO];
}
阵列中的ViewController只是普通的UIViewController
我已将这些类中的此属性设置为:
self.navigationItem.hidesBackButton = YES;
我的问题:这是实现UITabBarController行为的正确方法吗?没有测试它,但它看起来不错,除了
popViewControllerAnimated
。我会改用PoptorootViewController激活的
(以防控制器本身使用导航控制器)。为什么不使用UITabBarController呢?除显示“选项卡栏”外,您没有使用导航控制器的任何功能。因为只有Apple才允许将UtiAbbarController添加到应用程序的根窗口中。