Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the title of a navigation bar inside a tab bar controller

Well in my app I have a navigation controller with a table view, and when pressing a button a tab controller opens. In its first tab, I want the title of the navigation bar to be set.

Here is an image of my storyboard just to make sure we undestand each other.

enter image description here

This is my code that supposed to be working. I had used this code, when trying to open a single view and not a tab controller and it was working properly. So I guess I must change something.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{       
        SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:@"SkiCenter" bundle:[NSBundle mainBundle]];
        myDetViewCont.ski_center = [centers objectAtIndex:indexPath.row];
        UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        [[self navigationController] pushViewController:[storyBoard instantiateViewControllerWithIdentifier:@"SkiCenterIds"] animated:YES];
        //[self.navigationController pushViewController:myDetViewCont animated:YES]; // "Pushing the controller on the screen"
        [myDetViewCont release]; // releasing controller from the memory
        myDetViewCont = nil;        
    }

Where Skicenter is the name of the class for my first tab and SkiCenterIds is the identifier of my tab controller in storyboard.

Code in Skicenter.m is:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    self.navigationItem.title = ski_center;        
}

but I do not see any title. So what I have done wrong? I have also tried this:

[self.navigationController setTitle:@"Live"];

or

self.title=ski_center;

the ski_center has value because it is printed out normally in the NSLog.

like image 310
ghostrider Avatar asked Sep 08 '12 10:09

ghostrider


People also ask

What is a navigation bar tab?

Tab bars use bar items to navigate between mutually exclusive panes of content in the same view.

How do I add a tab bar to my navigation controller?

To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.

What is the use of tab bar controller?

The tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is, but may also be subclassed. Each tab of a tab bar controller interface is associated with a custom view controller.


1 Answers

Simple!

[self.tabBarController setTitle:@"Title"];
like image 153
nithinreddy Avatar answered Oct 05 '22 04:10

nithinreddy