【发布时间】:2011-11-29 14:34:00
【问题描述】:
我的 AppDelegate.h
//
// AppDelegate.h
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *window;
UITabBarController *tabBarController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end
我的 AppDelegate.m
//
// AppDelegate.m
//
#import "AppDelegate.h"
#import "AppNavigationController.h"
#import "ExamViewController.h"
#import "SignsViewController.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tabBarController = _tabBarController;
- (void)dealloc
{
[_tabBarController release];
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
// Initializating our Tab Bar Controller
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
// Exam Controller Setup
ExamViewController *examViewController = [[ExamViewController alloc] initWithStyle:UITableViewStylePlain];
AppNavigationController *examNavigationController = [[AppNavigationController alloc] initWithRootViewController:examViewController];
examViewController.title = @"Экзамен";
examViewController.tabBarItem.image = [UIImage imageNamed:@"icon_exam.png"];
// -------------------------------------
// Signs Controller Setup
SignsViewController *signsViewController = [[SignsViewController alloc] initWithStyle:UITableViewStylePlain];
AppNavigationController *signsNavigationController = [[AppNavigationController alloc] initWithRootViewController:signsViewController];
signsViewController.title = @"Знаки";
signsViewController.tabBarItem.image = [UIImage imageNamed:@"icon_signs.png"];
// -------------------------------------
[tabBarController setViewControllers:[NSArray arrayWithObjects:examNavigationController, signsNavigationController, nil]];
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[examNavigationController release];
[examViewController release];
[signsNavigationController release];
[signsViewController release];
return YES;
}
我还有空的 UINavigationController。
我想要实现的是为所有使用它的视图控制器定制导航栏
例如:现在我只有两个视图控制器,现在我将 self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 放在 ExamViewController.m 和 SignsViewController.m 的 viewDidLoad 方法中
但可能我想添加两个或更多选项卡并想在一个地方自定义导航栏。
那么问题来了:如何在一个地方自定义导航栏,使其在每个视图控制器中看起来都一样,而不在 viewDidLoad 方法中在每个视图控制器中自定义它?
【问题讨论】:
标签: iphone uinavigationcontroller uinavigationbar