我尝试使用带有导航栏的“选项卡式应用程序”。默认情况下,标签栏工作正常,但我无法打开导航栏。我找到了一些关于插入导航栏之类的东西,但我发现的所有东西都是几年前的,所以不要帮我。而且最近的东西已经过时了,因为 iOS5 和新版本的 Xcode..
谁能指出我正确的方向来结合 a 来解决这个问题?
请记住以下事实:
最佳答案
以下是您如何以编程方式实现它。
删除 [appName]-Info.plist 中对主要 xib 的引用
在 main.m 中,加载您的委托(delegate):
int retVal = UIApplicationMain(argc, argv, nil, @"myAppDelegate");
在应用程序委托(delegate)中,加载 tabBar、导航 Controller 和导航 Controller 中的 View 。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// create window since nib is not.
CGRect windowBounds = [[UIScreen mainScreen] applicationFrame];
windowBounds.origin.y = 0.0;
[self setWindow:[[UIWindow alloc] initWithFrame:windowBounds]];
// View Controllers for tabController (one viewController per tab)
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];
// first tab has view controller in navigation controller
FirstView *firstView = [[FirstView alloc] initWithNibName:@"FirstView" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstView];
[viewControllers addObject:navController];
SecondView *secondView = [[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[viewControllers addObject:secondView];
// create the tab controller and add the view controllers
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:viewControllers];
// add tabbar and show
[[self window] addSubview:[tabController view]];
[self.window makeKeyAndVisible];
return YES;
}
关于iphone - 结合 UITabBarController 和 UINavigationController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8044668/