2012-04-07 59 views
1

我瘋了解決這個問題。向UINavigationController添加標題+按鈕

我已經在我的AppDelegate.m 基本上是一個導航控制器+標籤欄下面的代碼鏈接到2 tableviewcontroller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    ElencoSpese *elenco=[[ElencoSpese alloc] init]; 
    [email protected]"Prova 123"; 

    ElencoSpese *elenco2=[[ElencoSpese alloc] init]; 
    [email protected]"Prova 222"; 

    UITabBarController *tabMenu = [[UITabBarController alloc] init]; 
    tabMenu.viewControllers=[NSArray arrayWithObjects:elenco, elenco2, nil]; 


    UINavigationController *navig=[[UINavigationController alloc] initWithRootViewController:tabMenu]; 
    self.window.rootViewController=navig; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

ElencoSpeseTableViewController,它工作正常。我想補充"title"這個窗口和「+」和"Edit"上的NavigationBar ....

我試過上面的按鈕來取消註釋在tableviewcontroller的方法的loadView如下:沒有結果

// Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
self.navigationItem.rightBarButtonItem = self.editButtonItem; 

我alsto中的appdelegate試圖設置標題....沒什麼......

回答

0

的視圖 - 控制被嵌入的TabBar控制器,其在navigationcontroller推。所以,你應該訪問像這樣的navigationitem:

self.tabBarController.navigationItem.rightBarButtonItem = self.editButtonItem; 
+0

沒辦法....我添加(無結果...):自.window.rootViewController.tabBarController.navigationItem.title = @ 「僑」;自動窗口控制器。謝謝他幫助 – 2012-04-07 11:50:16

+0

好的!現在,它的工作!謝謝! – 2012-04-07 11:58:39

0

該窗口的標題可以給出如下

行後,在你的代碼

self.window.rootViewController=navig; 

只需添加

self.tabbarController.navigationItem.title = @"YOUR TITLE"; 

這將幫助您給出標題

+0

沒辦法....我添加了(沒有結果...):self.window.rootViewController.tabBarController.navigationItem.title = @「ciao」;自動窗口控制器。感謝支持 – 2012-04-07 11:51:44

+0

好了,現在可以使用!謝謝!!! – 2012-04-07 11:58:57

1

做這樣的..

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    ElencoSpese *elenco=[[ElencoSpese alloc] init]; 
    [email protected]"Prova 123"; 

    ElencoSpese *elenco2=[[ElencoSpese alloc] init]; 
    [email protected]"Prova 222"; 
    UINavigationController *navig=[[UINavigationController alloc]  initWithRootViewController:elenco]; 
UINavigationController *navig1 =[[UINavigationController alloc] initWithRootViewController:elenco2]; 

    UITabBarController *tabMenu = [[UITabBarController alloc] init]; 
    tabMenu.viewControllers=[NSArray arrayWithObjects:navig, navig1, nil]; 

    self.window.rootViewController=tabMenu; 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

然後每個TableViewController -viewDidLoad添加這樣

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = @"Calculator"; 
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(yourSelectorMethod)]; 

    UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(yourSelectorMethod1)]; 

    self.navigationItem.leftBarButtonItem = item; 
    self.navigationItem.rightBarButtonItem = item1; 
}