如何使用选项卡栏在视图之间移动

发布于 2025-01-01 02:56:33 字数 482 浏览 0 评论 0原文

我正在做一个基于 SingleView 的应用程序,其中我有许多 UIviewcontroller 类子类,用于从一个视图移动到另一个视图。我在其中一个视图中有一个选项卡栏,并且希望在单击选项卡时与其他视图进行通信。所以请告诉我该怎么做,我被困在这里了。 我有名为

LoginPage.h/.m/.xib

Myservices.h/.m/.xib

History.h/.m/.xib

Profile.h/.m/.xib

MyRecentRequest.h/.m/.xib

的 类我从登录页面进入,它移至“我的服务”视图。 我在底部添加了选项卡栏,并添加了两个选项卡项目,总共有 4 个选项卡栏项目,分别命名为 Myservices、history、MyrecentRequest 和 profile。

现在我想将选项卡栏与其他类连接,以便当我单击选项卡项时,应该出现该特定类的相应视图,那么我该如何执行此操作?请向我提供示例代码。

I am doing an application which is of SingleView BASED Application,where i have many UIviewcontrollerclass subclasses for moving from one view to another view.i have a tab bar in one of the view and want to communicate with others view when click on a tab.so plz tell me how can i do it i am stuck here.
i have classes called

LoginPage.h/.m/.xib

Myservices.h/.m/.xib

History.h/.m/.xib

Profile.h/.m/.xib

MyRecentRequest.h/.m/.xib

when i enter from login page it moves to Myservices view.
There i have added Tab bar at the bottom and added two more tab Items and totally have 4 tab bar items naming Myservices,history,MyrecentRequest and profile.

Now i want to connect the tab bar with other class so that when i click on tab item respective view should appear of that particular classs so how can i do this? please provide me sample code.

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

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

发布评论

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

评论(2

執念 2025-01-08 02:56:33

首先,如何通过 IB 或代码维护 tabBar。下面如果通过代码。您需要为每个 tabItem 分配一个包含所有所需 viewController 的 tabBar,下面是具有 2 个 tabItem 的示例:

UITabBarController* tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:8];

ViewController1* vC1 = [[ViewController1 alloc] init];
UINavigationController* navController1 = [[UINavigationController alloc] initWithRootViewController:vC1];
[vC1 release];      
navController1.tabBarItem.image = [UIImage imageNamed:@"navController1_image.png"];
[localViewControllersArray addObject:navController1];
[navController1 release]; 

ViewController2* vC2 = [[ViewController2 alloc] init];
UINavigationController* navController2 = [[UINavigationController alloc] initWithRootViewController:vC2];
navController2.tabBarItem.image = [UIImage imageNamed:@"navController2_image.png"];
[vC2 release];      
[localViewControllersArray addObject:navController2];
[navController2 release]; 

tabBarController.viewControllers = localViewControllersArray;
    self.window.rootViewController = tabbarController;
[localViewControllersArray release];
    [tabBarController release];

这样您就可以通过代码维护 tabBar,这样如果选择了选项卡,就会显示相应的视图,在此示例中每个选项卡中都使用导航控制器来提供导航,如果只需要 1 个视图,您可以避免使用导航控制器。

first of all how u r maintaining the tabBar, either from IB or code. The below if by code. You need to alloc a tabBar with all the viewControllers required into each tabItem, the below one is sample with 2 tabItems:

UITabBarController* tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:8];

ViewController1* vC1 = [[ViewController1 alloc] init];
UINavigationController* navController1 = [[UINavigationController alloc] initWithRootViewController:vC1];
[vC1 release];      
navController1.tabBarItem.image = [UIImage imageNamed:@"navController1_image.png"];
[localViewControllersArray addObject:navController1];
[navController1 release]; 

ViewController2* vC2 = [[ViewController2 alloc] init];
UINavigationController* navController2 = [[UINavigationController alloc] initWithRootViewController:vC2];
navController2.tabBarItem.image = [UIImage imageNamed:@"navController2_image.png"];
[vC2 release];      
[localViewControllersArray addObject:navController2];
[navController2 release]; 

tabBarController.viewControllers = localViewControllersArray;
    self.window.rootViewController = tabbarController;
[localViewControllersArray release];
    [tabBarController release];

In this way u can maintain the tabBar by code, so that if tab is selected respective view will be shown, in this example a navigation controller is used in each tab to provide navigation, if only 1 view is required u can avoid the navigation controller..

焚却相思 2025-01-08 02:56:33

为此,以下代码用于动态选择导航控制器并选择选择哪个选项卡。

-(void)applicationDidFinishLaunching:(UIApplication *)application {

// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate=self;
tabBarController=[[UITabBarController alloc] init];

mainDashBoard=[[DashBoard alloc] initWithNibName:@"DashBoard" bundle:nil];
mainSearchView=[[SearchView alloc] initWithNibName:@"SearchView" bundle:nil];
mainMoreView=[[MoreView alloc] initWithNibName:@"MoreView" bundle:nil];

UINavigationController *nvCtr0=[[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1=[[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2=[[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3=[[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4=[[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];

tabBarController.viewControllers=[NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];

nvCtr0.tabBarItem.enabled=NO;
nvCtr4.tabBarItem.enabled=NO;
 delegate.tabBarController.selectedIndex = 0;
[window tabBarController.view];
}

这可能有助于创建应用程序

For that the following code is use to dynamically select the navigation controller and select the which tab is select.

-(void)applicationDidFinishLaunching:(UIApplication *)application {

// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate=self;
tabBarController=[[UITabBarController alloc] init];

mainDashBoard=[[DashBoard alloc] initWithNibName:@"DashBoard" bundle:nil];
mainSearchView=[[SearchView alloc] initWithNibName:@"SearchView" bundle:nil];
mainMoreView=[[MoreView alloc] initWithNibName:@"MoreView" bundle:nil];

UINavigationController *nvCtr0=[[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1=[[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2=[[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3=[[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4=[[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];

tabBarController.viewControllers=[NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];

nvCtr0.tabBarItem.enabled=NO;
nvCtr4.tabBarItem.enabled=NO;
 delegate.tabBarController.selectedIndex = 0;
[window tabBarController.view];
}

this may be helpful to crate the application

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