Hi, I have a UITableViewController, and double clicking on the table cells I am loading a custom tabbar controller. All my tabbar items will have hierarchy of views. My problem is that I am not able to push, on the custom tabbar items another uiview. I get self.navigationcontroller as null in my custom tabbarviewcontroller although I am able to get the proper value of self.navigationcontroller in my UITableViewController. Also I am able to view the navigationbar title on my tabbaritem view, but then why am I not able to push another view on that? Can anybody please help me out, below is my code.
MyTableViewController(this is the controller where I can get the value self.navigationcontroller),
Code:
- (void)viewDidLoad {
//Initializing Custom Tabbar controller that has 2 other tabbar views
UITransTabViewController *transtvController = [[UITransTabViewController alloc] initWithNibName:@"TransTabViewController" bundle:nil];
self.transtabViewController = transtvController;
[transtvController release];
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
//This does push the custom tabbar controller onto the UITableViewController
if(row==0){
[self.navigationController pushViewController:self.transtabViewController animated:YES];
}
}
UITransTabViewController code(this is my custom tabbar controller),
Code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization of my two tab items on the tabbar controller
ArrivalsTabViewController *arrTabViewController = [[ArrivalsTabViewController alloc] initWithNibName:@"Arrivals" bundle:nil];
DeparturesTabViewController *depTabViewController = [[DeparturesTabViewController alloc] initWithNibName:@"Departures" bundle:nil];
NSArray *array = [[NSArray alloc] initWithObjects:arrTabViewController, depTabViewController, nil];
self.viewControllers = array;
[self.view addSubview:arrTabViewController.view];
self.selectedViewController = depTabViewController;
[array release];
[arrTabViewController release];
[depTabViewController release];
}
return self;
}
- (void)viewDidLoad {
NSLog(@"MY NAV CONTROLLER IN TRANSTABVIEWCONTROLLER IS = %@", self.navigationController);
if (self.navigationController == nil)
NSLog(@"navigation is nil");
if (self.parentViewController.navigationController == nil)
NSLog(@"parent navigation is nil");
//here i get both navigation and parent navigation as nil..
tabBar.selectedItem = arrivalsTabBarItem;
[super viewDidLoad];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item == arrivalsTabBarItem) {
UIViewController *arrViewController = [viewControllers objectAtIndex:0];
[self.selectedViewController.view removeFromSuperview];
[self.view addSubview:arrViewController.view];
self.selectedViewController = arrViewController;
} else if (item == departuresTabBarItem) {
UIViewController *depViewController = [viewControllers objectAtIndex:1];
[self.selectedViewController.view removeFromSuperview];
[self.view addSubview:depViewController.view];
self.selectedViewController = depViewController;
}
}
I have a button in my ArrivalsTabViewController which is the first tab item in my custom controller,
Code:
- (IBAction)findArrivals:(id)sender {
MyViewController *myController=
[[MyViewController alloc]initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:myController animated:YES];
[myController release];
}
On click of the button, I am not able to push myController on the tabbar item view. Please let me know if I have not made my self clear enough.