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.
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;
// Do any additional setup after loading the view from its nib.
self.navigationItem.title = ski_center;
Basically I don't know if you did't noticed but I got it work like this:
I assigned my tab bar Controller a new class.
I did the following:
add it to app delegate.h
@property (nonatomic,retain) NSString *center;
add it to mainmap.m
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; delegate.center=[centers objectAtIndex:indexPath.row];
and in mytabbarcontroller.m
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; ski_center=delegate.center; self.navigationItem.title = ski_center;