私はモーダルビューを表示する必要があります。モーダル表示される必要があるViewControllerは、下部にUIToolbarを持つ必要があります。このツールバーには、3つの要素を持つ1つのUISegmentedControllerがあります。 (タブバーを考える)。私が持っているのViewControllerモーダルを提示のViewControllerでUIToolbarとUINavigationController
:
-(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];
}
アレイ内viewcontrollersが普通UIViewControllersあります。
私はそれらのクラスでこのプロパティを設定しています
self.navigationItem.hidesBackButton = YES;
私の質問:これはUITabBarControllerの挙動を達成するための適切な方法ですか?
なぜUITabBarControllerを使用しないのですか? 「タブバー」を表示する以外に、ナビゲーションコントローラの機能を使用していません。 – ughoavgfhw
UITabBarControllerはAppleがアプリケーションのルートウィンドウに追加することのみ許可されているためです。 – LuckyLuke