Reputation: 11
I'm getting crazy to solve this problem.
I've the following code in my AppDelegate.m
Basically a navigation controller + tab bar that link to 2 tableviewcontroller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ElencoSpese *elenco=[[ElencoSpese alloc] init];
elenco.tabBarItem.title=@"Prova 123";
ElencoSpese *elenco2=[[ElencoSpese alloc] init];
elenco2.tabBarItem.title=@"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
is a TableViewController
and it works ok. I want to add "title"
to this window and "+" and "Edit"
button on top of the NavigationBar
....
I've tried to uncomment the following in the loadview method of the tableviewcontroller: no result
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
I've alsto tried in the appdelegate to set title....nothing...
Upvotes: 1
Views: 631
Reputation: 1643
Do Like this..
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
ElencoSpese *elenco=[[ElencoSpese alloc] init];
elenco.tabBarItem.title=@"Prova 123";
ElencoSpese *elenco2=[[ElencoSpese alloc] init];
elenco2.tabBarItem.title=@"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;
}
Then each TableViewController -viewDidLoad add like this
-(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;
}
Upvotes: 1
Reputation: 5267
the title for the window can be given as below
after the line in your code
self.window.rootViewController=navig;
just add
self.tabbarController.navigationItem.title = @"YOUR TITLE";
this will help you to give title
Upvotes: 0
Reputation: 35384
The viewcontroller is embedded in a tabbar-controller, which is pushed in a navigationcontroller. So you should access the navigationitem like so:
self.tabBarController.navigationItem.rightBarButtonItem = self.editButtonItem;
Upvotes: 0