工具栏 +导航栏 +分段控制?

发布于 2024-12-17 11:33:48 字数 1170 浏览 0 评论 0原文

我正在尝试找到一种方法来布局应用程序,该应用程序包括底部的选项卡栏、顶部的导航栏以及导航栏上用于切换视图的一行按钮(在第一个选项卡上)。

我画了一个非常粗略的草图(抱歉!),但我希望它能够说明意图。

应用布局 底部有两个选项卡(tab1 和 tab2)。

当选择 Tab1 时,导航栏将有 3 个按钮,将显示不同的视图(tab1_1、tab1_2、tab1_3)。

当选择 Tab2 时,导航栏不会显示任何按钮,而是一些简单的文本。

此时,我的应用程序委托的 didFinishLaunchingWithOptions 中有以下方案:

    UIViewController *viewController1 = [[Tab1_ViewController alloc] initWithNibName:@"Tab1_ViewController" bundle:nil];
    UIViewController *viewController2 = [[Tab2_ViewController alloc] initWithNibName:@"Tab2_ViewController" bundle:nil];

    tab1NavController = [[UINavigationController alloc] initWithRootViewController:viewController1];
    tab2NavController = [[UINavigationController alloc] initWithRootViewController:viewController2];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:tab1NavController, tab2NavController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

我想知道是否需要重做我正在做的事情以实现如图所示的布局。

任何帮助将不胜感激,谢谢!

I'm trying to find a way to layout an application that includes a tab bar on the bottom, a navigation bar on the top, and a row of buttons on the navigation bar that switches views (on the first tab).

I've drawn a very rough sketch (sorry!), but I hope it illustrates the intent.

App layout
On the bottom, there are two tabs (tab1, and tab2).

When Tab1 is selected, the navigation bar will have 3 buttons that will show different views (tab1_1, tab1_2, tab1_3).

When Tab2 is selected, the navigation bar won't show any buttons, but rather some simple text.

At this point, I have the following scheme in my application delegate's didFinishLaunchingWithOptions:

    UIViewController *viewController1 = [[Tab1_ViewController alloc] initWithNibName:@"Tab1_ViewController" bundle:nil];
    UIViewController *viewController2 = [[Tab2_ViewController alloc] initWithNibName:@"Tab2_ViewController" bundle:nil];

    tab1NavController = [[UINavigationController alloc] initWithRootViewController:viewController1];
    tab2NavController = [[UINavigationController alloc] initWithRootViewController:viewController2];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:tab1NavController, tab2NavController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

I was wondering if I need to redo how I'm doing things in order to achieve the layout as in the picture.

Any help would be appreciated, thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2024-12-24 11:33:48

我已经为我当前的项目做到了这一点...我希望这会对您有所帮助...

首先在您的第一个 viewController [您给出的第一个草图]处使用 UITabbarController

对于您的第一个视图,请使用此代码....

 - (void)viewDidLoad {
[super viewDidLoad];

dashBoardView = [[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:nil];
dashBoardView.title = @"dashBoardView";
UINavigationController *mydashboarController = [[[UINavigationController alloc] initWithRootViewController:dashBoardView] autorelease];
mydashboarController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:mydashboarController];
[dashBoardView release];

ordersView = [[OrdersViewController alloc] initWithNibName:@"OrdersViewController" bundle:nil];
    ordersView.title = @"ordersView";
UINavigationController *myorderController = [[[UINavigationController alloc] initWithRootViewController:ordersView] autorelease];
myorderController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderController];
[ordersView release];

orderList = [[OrderListViewController alloc] initWithNibName:@"OrderListViewController" bundle:nil];
orderList.title = @"orderList";
UINavigationController *myorderListController = [[[UINavigationController alloc] initWithRootViewController:orderList] autorelease];
myorderListController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderListController];
[orderList release];

productView = [[ProductViewController alloc] initWithNibName:@"ProductViewController" bundle:nil];
    productView.title = @"productView";
UINavigationController *myproductController = [[[UINavigationController alloc] initWithRootViewController:productView] autorelease];
[listOfViewControllers addObject:myproductController];
[productView release];

[self.tabBarController setViewControllers:listOfViewControllers animated:YES];

NSArray *segmentTextContent = [NSArray arrayWithObjects:NSLocalizedString(@"Dashboard", @""),NSLocalizedString(@"Order", @""),
                               NSLocalizedString(@"Product", @""),NSLocalizedString(@"More", @""),
                               nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 400, 40);
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];

//defaultTintColor = [segmentedControl.tintColor retain];   // keep track of this for later

segmentedControl.tintColor = [UIColor colorWithHue:8.0 saturation:8.0 brightness:8.0 alpha:1.0];
segmentedControl.alpha = 0.8;

self.navigationItem.titleView = segmentedControl;
[segmentedControl release]; 
}

如果您不清楚,请敲...

I have done this for my current project...i hope this will help you....

At first take UITabbarController at your first viewController [first sketch you have given]

For your first view use this code....

 - (void)viewDidLoad {
[super viewDidLoad];

dashBoardView = [[DashboardViewController alloc] initWithNibName:@"DashboardViewController" bundle:nil];
dashBoardView.title = @"dashBoardView";
UINavigationController *mydashboarController = [[[UINavigationController alloc] initWithRootViewController:dashBoardView] autorelease];
mydashboarController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:mydashboarController];
[dashBoardView release];

ordersView = [[OrdersViewController alloc] initWithNibName:@"OrdersViewController" bundle:nil];
    ordersView.title = @"ordersView";
UINavigationController *myorderController = [[[UINavigationController alloc] initWithRootViewController:ordersView] autorelease];
myorderController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderController];
[ordersView release];

orderList = [[OrderListViewController alloc] initWithNibName:@"OrderListViewController" bundle:nil];
orderList.title = @"orderList";
UINavigationController *myorderListController = [[[UINavigationController alloc] initWithRootViewController:orderList] autorelease];
myorderListController.navigationBar.barStyle = UIBarStyleBlack;
[listOfViewControllers addObject:myorderListController];
[orderList release];

productView = [[ProductViewController alloc] initWithNibName:@"ProductViewController" bundle:nil];
    productView.title = @"productView";
UINavigationController *myproductController = [[[UINavigationController alloc] initWithRootViewController:productView] autorelease];
[listOfViewControllers addObject:myproductController];
[productView release];

[self.tabBarController setViewControllers:listOfViewControllers animated:YES];

NSArray *segmentTextContent = [NSArray arrayWithObjects:NSLocalizedString(@"Dashboard", @""),NSLocalizedString(@"Order", @""),
                               NSLocalizedString(@"Product", @""),NSLocalizedString(@"More", @""),
                               nil];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0, 0, 400, 40);
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];

//defaultTintColor = [segmentedControl.tintColor retain];   // keep track of this for later

segmentedControl.tintColor = [UIColor colorWithHue:8.0 saturation:8.0 brightness:8.0 alpha:1.0];
segmentedControl.alpha = 0.8;

self.navigationItem.titleView = segmentedControl;
[segmentedControl release]; 
}

If it is not clear to you then please knock...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文