2012-04-07 18 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; 
} 

ElencoSpeseにリンクナビゲーションコントローラ+タブバーがTableViewControllerできたし、それがうまく動作。私はtableviewcontrollerのloadViewメソッドで次のようにコメントを解除するために、このウィンドウに"title"、私が試したNavigationBar ....

の最上部の「+」と"Edit"ボタンを追加したい:なし結果を

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

のViewControllerがnavigationcontrollerにプッシュされタブバーコントローラ、中に埋め込まれています。だから、あなたはそうのようなnavigationitemにアクセスする必要があります

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

まさかのように追加-viewDidLoad ....私が追加した(結果なしで...):自己を.window.rootViewController.tabBarController.navigationItem.title = @ "ciao";サブタイトル。おかげで彼は助ける –

+0

よろしく!今それは動作します!ありがとう! –

0

ウィンドウのタイトルは、単に追加のコード

self.window.rootViewController=navig; 

の中の行の後

以下のように与えることができ

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

これはあなたのタイトルを与えるのに役立ちます

+0

いいえ....私は(結果なしで...)を追加しました:self.window.rootViewController.tabBarController.navigationItem.title = @ "ciao";サブタイトル。サポートありがとう –

+0

今、それは動作します!感謝!!! –

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がこの

-(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; 
} 
関連する問題