XCode TabBar 应用程序 - 多个视图?
我一直致力于创建一个底部带有选项卡的应用程序,但能够使用 tabBar 应用程序显示的笔尖上我自己的链接切换视图。
我一直在试图找到一个这样的例子,但是 xcode 4.2(无论是在 ios5.0 或更早版本上)不会创建 mainwindow.xib,所以我必须找到一种以编程方式创建此文件的方法,如下所示:
#import "AppDelegate.h"
#import "HomeViewController.h"
#import "ViewListViewController.h"
#import "ShareViewController.h"
#import "FriendsViewController.h"
#import "SettingsViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UIViewController *viewListViewController = [[ViewListViewController alloc] initWithNibName:@"ViewListViewController" bundle:nil];
UIViewController *shareViewController = [[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];
UIViewController *friendsViewController = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil];
UIViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController, viewListViewController, shareViewController, friendsViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我的 AppDelegate 中的这段代码.m 工作正常,我可以在选项卡之间完美切换。我遇到的问题是,我将向页面添加图形,并使用它们作为按钮在视图之间切换,以添加/编辑/删除数据库中的数据(下一步我必须学习做的单独问题)。
我发现的大多数示例都是使用 tabBar 或 uiNavigation 启动应用程序,并在 UIView 之间进行切换。我还没有找到一个例子可以清楚地展示如何做我想做的事情。我创建 tabBar 应用程序作为基本模板的方法是否错误,或者可以这样做吗?每个选项卡可能有多个执行功能的视图,但我需要能够在 tabBar 框架内创建它们并在它们之间切换。
提前致谢,
Silver Tiger
-更新:-
阅读了一些内容后,我现在认为 aUINavigationController 不是我想要的。我需要的是一种创建自定义按钮的方法,以允许我切换视图,因为我将在内容中使用的按钮要么是图形,要么是图形背景上的透明按钮。是否可以使用自定义按钮来推送新视图,同时仍然保持 tabBar 始终可见?我的结构如下所示,
Home
Add
Edit
delete
ViewList - Single page to view list
Share - Single page to send emails / invites
Friends
Add
Edit
Delete
Settings - Single page for app settings/preferences
所以本质上我实际上只有 2 个选项卡,我将在其中推送新视图,但 UINavigationController 似乎不适合我正在使用的方法,因为我没有使用顶部的单个栏切换视图。
I have been working to create an app with tabs at the bottom, but with the ability to switch views with my own links on the nib's that the tabBar app displays.
I have been trying to find an example of this but xcode 4.2 (whether on ios5.0 or earlier) does not create a mainwindow.xib, so i have had to find a way to create this programmataiically as follows:
#import "AppDelegate.h"
#import "HomeViewController.h"
#import "ViewListViewController.h"
#import "ShareViewController.h"
#import "FriendsViewController.h"
#import "SettingsViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
UIViewController *viewListViewController = [[ViewListViewController alloc] initWithNibName:@"ViewListViewController" bundle:nil];
UIViewController *shareViewController = [[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];
UIViewController *friendsViewController = [[FriendsViewController alloc] initWithNibName:@"FriendsViewController" bundle:nil];
UIViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setDelegate:self];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:homeViewController, viewListViewController, shareViewController, friendsViewController, settingsViewController, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
This code in my AppDelegate.m works fine and i can switch between the tabs perfectly. The issue I am having is that I will be adding graphics to the pages and using them as buttons to switch between views for adding/editing/deleting data from a database (separate issue I will have to learn to do next).
Most examples i have found start the app with either a tabBar, or a uiNavigation with UIViews to switch between. I have yet to find an example that will clearly show how to do what I am looking to do. Is my approach wrong to create the tabBar application as my base template for this, or can this be done? Each tab may have multiple views that perform functions, but I need to be able to create and switch between them within the tabBar framework.
thanks in advance,
Silver Tiger
-UPDATE:-
AFter reading up a bit I am now thinking that aUINavigationController is not what I am looking for. What I need is a way for a custom button that I create to allow me to switch views, as the buttons I will be using in my content will be either graphics or transparent on top of a graphic background. Is it possible to use custom buttons to push new views while still keeping the tabBar visible at all times? My structure would be as below
Home
Add
Edit
delete
ViewList - Single page to view list
Share - Single page to send emails / invites
Friends
Add
Edit
Delete
Settings - Single page for app settings/preferences
so essentially i'd only really have 2 of the tabs where i would be pushing new views but the UINavigationController doesn't seem to fit the method i am using since i am not using a single bar up top to switch views.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UINavigationController
和UITabBarController
都是视图控制器的控制器。在这个函数中,它们的工作方式是相同的。但也存在一些差异。使用此作为指导:UINavigationController: 此处,顶部通常有一个导航栏。您将其他视图控制器“推”到“堆栈”上,导航控制器负责处理顶部的所有按钮以及动画等。通常(但并非总是)这是通过表视图实现的。
UITabBarController:在这里,标签栏始终位于底部,因此只有当用户通常必须访问某些内容(无论用户位于视图层次结构中的哪个位置)时,这才有意义。查看“闹钟”应用程序的典型示例。
组合:如果您想将两者组合起来,请从标签栏控制器开始。然后,您可以将单独的导航控制器分配给一个或多个选项卡栏项目。导航控制器依次管理它们的视图控制器。确保您的 UI 不会因屏幕顶部和底部的导航控件而变得过于混乱。查看 iTunes 应用程序的典型示例。
顺便说一句,如果一个视图需要更多空间,您始终可以使这些控件消失(例如,在 iPod 应用程序中,当转到“正在播放”时,选项卡栏会被工具栏取代)。
Both
UINavigationController
andUITabBarController
are controllers of view controllers. In this function, they work the same way. But there are some differences. Use this as a guide:UINavigationController: Here you usually have a navigation bar at the top. You "push" other view controllers onto a "stack" and the navigation controller takes care of all the buttons on top to go back and forth as well as the animations, etc. Often, but not always, this is implemented with table views.
UITabBarController: Here you have the tab bar at the bottom at all times, so this should only make sense if there are things the user would typically have to access regardless of where she is in the view hierarchy. Look at the Alarm Clock app for a typical example.
Combination: If you want to combine the two, you start with the tab bar controller. You can then assign separate navigation controllers to one or more tab bar items. The navigation controllers in turn manage their view controllers. Make sure your UI does not get too cluttered with navigation controls at the top and bottom of the screen. Look at the iTunes App for a typical example.
BTW, you can always make these controls disappear, if one view needs more space (e.g. in the iPod app the tab bar gets replaced by a toolbar when going to "Now Playing").