2013-02-06 89 views
0

以我標籤基於應用程序委託我添加導航控制器像下面,navigationcontroller標題和按鈕

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 

UIViewController *viewController3 = [[view1 alloc] initWithNibName:@"view1" bundle:nil]; 
UIViewController *viewController4 = [[view2 alloc] initWithNibName:@"view2" bundle:nil]; 
UIViewController *viewController5 = [[view3 alloc] initWithNibName:@"view3" bundle:nil]; 
self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = @[viewController1, viewController2,viewController3,viewController4,viewController5]; 
navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController]; 
[self.window addSubview:[navigationController view]]; 
self.window.rootViewController = self.navigationController; 

我將不能夠添加在每個視圖的標題。 ?雖然增加它不顯示標題請幫助我解決這個問題

+0

http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/NavigationControllers.html – fionbio

+0

我按照文檔進行了操作,但未顯示應該如何處理我改變了編碼? –

+0

您被分配FirstViewController並分配給UIViewController對象。 FirstViewController * vc1 = [[FirstViewController alloc] init .....]; – Durgaprasad

回答

1

使用婁代碼...

在這裏,我添加UINavigationController到每個標籤還可以指派標題標籤,也爲UINavigationBar像波紋管......

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5; 
    UINavigationController *navviewController1 , *navviewController2, *navviewController3, *navviewController4, *navviewController5; 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     viewController1 = [[[YourViewController1 alloc] initWithNibName:@"YourViewController1" bundle:nil] autorelease]; 
     navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1]; 
     navviewController1.title = @"Home"; 
     //  navviewController1.navigationBarHidden=YES; 

     viewController2 = [[[YourViewController2 alloc] initWithNibName:@"YourViewController2" bundle:nil] autorelease]; 
     navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2]; 
     //  navviewController2.navigationBarHidden=YES; 
     navviewController2.title = @"HowItsWork"; 

     viewController3 = [[[YourViewController3 alloc] initWithNibName:@"YourViewController3" bundle:nil] autorelease]; 
     navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3]; 
     //  navviewController3.navigationBarHidden=YES; 
     navviewController3.title = @"Join Us"; 


     viewController4 = [[[YourViewController4 alloc] initWithNibName:@"YourViewController4" bundle:nil] autorelease]; 
     navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4]; 
     //  navviewController4.navigationBarHidden=YES;  
     navviewController4.title = @"Become"; 

     viewController5 = [[[YourViewController5 alloc] initWithNibName:@"YourViewController5" bundle:nil] autorelease]; 
     navviewController5=[[UINavigationController alloc]initWithRootViewController:viewController5]; 
     //  navviewController4.navigationBarHidden=YES;  
     navviewController5.title = @"Contact Us"; 
     self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2,navviewController3,navviewController4,navviewController5, nil]; 
     self.window.rootViewController = self.tabBarController; 
    } 

    [self.window makeKeyAndVisible]; 
} 

2)或

你也可以像波紋管你的特定類的簡單分配標題...

-(void)viewWillAppear:(BOOL)animated{ 
    self.title = @"yourTitle"; 
} 

我希望這對您有所幫助......

0

在每一個視圖控制器viewDidLoad中 self.navigationcontroler.title = @ 「firstVC」;

0

「標題」是的UIViewControllerUINavigationController該屬性的UIViewController子類,您還可以訪問對象的UINavigationController,就像navviewController.title = @"myTitle";和更詳細的檢查Apple Docs。希望它會有所幫助。乾杯

0

您已將TabBar控制器添加到導航控制器中,因此無法添加標題並引發此問題。

嘗試在Tabbar控制器內添加每個導航控制器與View控制器。 我的意思是添加你的ViewController作爲導航控制器的根視圖控制器,然後添加到標籤欄控制器。

viewController1 = [[[YourViewController1 alloc] initWithNibName:@"YourViewController1" bundle:nil] autorelease]; 
     navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1]; 

現在,然後將此導航控制器添加到tabbar控制器中。對所有其他視圖控制器執行此操作