2011-11-29 59 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