2011-11-29 77 views
3

我AppDelegate.h自定义导航控制器的所有ViewControllers

// 
// 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。

我想要实现的东西是定制的导航栏对于使用它 举例而言,所有viewcontrollers:现在我只有两个viewcontrollers,现在我把self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;在viewDidLoad方法中ExamViewController.m和SignsViewController.m 但可能是我我想添加两个或多个标签,并想在一个地方自定义导航栏。 所以问题是:如何自定义导航栏在一个地方看每个viewcontroller相同,而无需在viewDidLoad方法中的每个viewcontroller中定制它?

回答

3

试试这个:.

  1. 重新创建视图控制器,让我们说ViewControllerTemplate.h
  2. 要箱子刚才设置的ViewControllerTemplate视图控制器每次设置的设计在.m文件
  3. 然后ViewControllerTemplate导航控制器.h作为它的超类,它将继承设计。

    ViewControllerTemplate *newController = [[ViewControllerTemplate alloc]init]; 
    
+0

我有文件夹模板和我AppNavigationController奠定了那里,这个问题如何自定义它的观点。 – nazarov

+0

谢谢,我已经把self.navigationBar.barStyle = UIBarStyleBlackOpaque;在AppNavigationController的viewDidLoad方法中。我试图把self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;之前但没有结果。 – nazarov

1

如果您使用的是iOS 5中,仅一种新的方式是UIAppearence。在这里看到:Custom Appearance for UIKit Controls

这里是另一个伟大的教程如何史蒂夫巴兰斯基定制iOS 5中的UI: User Interface Customization in iOS 5

+0

也许它可以用于第五版,但与其他用户一起使用...... – nazarov

+0

'UIAppearance'仅适用于iOS 5。如果您需要其他iOS版本的解决方案,shannogas答案是您可以做到的一种方式。 – Pfitz

相关问题