2012-04-07 2 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 и он работает нормально. Я не хочу, чтобы добавить "title" к этому окну и и "Edit" кнопки «+» в верхней части NavigationBar ....

Я попытался раскомментируйте в методе loadview в tableviewcontroller: нет результата

// 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 встроен в TabBar-контроллер, который выталкивается в navigationcontroller. Таким образом, вы должны получить доступ к navigationitem так:

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

Ни в коем случае .... Я добавил (без результатов ...): сам .window.rootViewController.tabBarController.navigationItem.title = @ "чао"; self.window.rootViewController.navigationItem.rightBarButtonItem = self.window.rootViewController.editButtonItem; Спасибо, что он помог –

+0

Хорошо! Теперь это работает! Спасибо! –

0

название для окна может быть задана как ниже

после строки в коде

self.window.rootViewController=navig; 

просто добавить

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

это поможет вам сообщить название

+0

Ни в коем случае .... Я добавил (без результатов ...): self.window.rootViewController.tabBarController.navigationItem.title = @ "ciao"; self.window.rootViewController.navigationItem.rightBarButtonItem = self.window.rootViewController.editButtonItem; Спасибо за поддержку –

+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 -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; 
} 
Смежные вопросы