-1

I am new to the iphone development.Currently I am doing a project using TABBED APPLICATION TEMPLATE which contains 4 tabs in which one is having a list of items in the table view and on clicking the table cell i would like to give a description page.I know that navigation have to be used and i am successful in bringing out the navigation but the problem now is i would like to have the tab bar in the detail page also .But in mine its not coming . Right now i am using this code to bring the navigation

In didfinishlaunching in appdelegate

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIViewController *viewController1 = [[[cardsAvailable1 alloc] initWithNibName:@"cardsAvailable1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[fetchcard1 alloc] initWithNibName:@"fetchcard1" bundle:nil] autorelease];
UIViewController *viewController3 = [[[registration alloc] initWithNibName:@"registration" bundle:nil] autorelease];
UIViewController *viewController4 = [[[logintab alloc] initWithNibName:@"logintab" bundle:nil] autorelease];


self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3,viewController4, nil];
self.tabBarController.selectedIndex = 3;

navigationController = [[UINavigationController alloc]
                        initWithRootViewController:self.tabBarController];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:navigationController.view];

[self.window makeKeyAndVisible];

[self.navigationController pushViewController:self.detailViewExample animated:YES];

and for the navigation on selection

What is the correct method to do it? Can any one suggest me solution for this?

Alan Haggai Alavi
  • 72,802
  • 19
  • 102
  • 127
user1288402
  • 35
  • 2
  • 7

2 Answers2

0

There is a mistake in your code or in your explanation. You are not building a Tabbed app as the first view in your window is the one of a NavigationController. And there is a dangerous thing in your code because the first view on the windows is the navigationcontroller.view but the rootViewController is the tabViewController one. Not very smart.

What you want to do is a Tabbed Application with a Navigation Controller in each tab:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] 
                                                    bounds]] autorelease];

UIViewController *viewController1 = [[[cardsAvailable1 alloc] 
                           initWithNibName:@"cardsAvailable1" bundle:nil] autorelease];
UIViewController *viewController2 = [[[fetchcard1 alloc] 
                                initWithNibName:@"fetchcard1" bundle:nil] autorelease];
UIViewController *viewController3 = [[[registration alloc] 
                              initWithNibName:@"registration" bundle:nil] autorelease];
UIViewController *viewController4 = [[[logintab alloc] 
                                  initWithNibName:@"logintab" bundle:nil] autorelease];

self.tabBarController = [[[UITabBarController alloc] init] autorelease];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:
    [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease], 
    [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease],
    [[[UINavigationController alloc] initWithRootViewController:viewController3] autorelease],
    [[[UINavigationController alloc] initWithRootViewController:viewController4] autorelease], 
nil];

self.tabBarController.selectedIndex = 3;

self.window.rootViewController = self.tabBarController;
[self.window addSubview:tabBarController.view];

[self.window makeKeyAndVisible];

UINavigationController * navController = [[tabBarController viewControllers] objectAtIndex:3];
[navController pushViewController:self.detailViewExample animated:YES];
Gabriel
  • 3,319
  • 1
  • 16
  • 21
0

okay what i did was that i had about 5 tabs and each one was having navigation controller

u can custumize the code below

//Initialize all the object of classes for Tabs and Navigation
Recipes *frstObj= [[Recipes alloc]init];
GalaryView *galObj = [[GalaryView alloc] init];
FavPageView *favObj = [[FavPageView alloc]init];
MyRecipes *addRec = [[MyRecipes alloc]init];
SearchSelection *searchTab = [[SearchSelection alloc] init];
//EnterContactsViewController *addRec = [[EnterContactsViewController alloc]initWithNibName:@"EnterContactsViewController_iPhone" bundle:nil];

[self.window addSubview:frstObj.view];


navContobj1 = [[UINavigationController alloc] init];
navContobj2 = [[UINavigationController alloc] init];
navContobj3 = [[UINavigationController alloc]init];
navContobj4 = [[UINavigationController alloc]init];
navContobj5 = [[UINavigationController alloc]init];

[navContobj1 pushViewController:frstObj animated:YES];
[navContobj2 pushViewController:galObj animated:YES];
[navContobj3 pushViewController:favObj animated:YES];
[navContobj4 pushViewController:searchTab animated:YES];
[navContobj5 pushViewController:addRec animated:YES];
[frstObj release];
[galObj release];
[favObj release];
[searchTab release];
[addRec release];

//Set Title
navContobj2.title = @"Galary";
navContobj3.title = @"Favoruite";
addRec.title = @"Add Recipe";
navContobj4.title = @"Search Recipes";


UITabBarController *tab = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
[tab setViewControllers:[NSArray arrayWithObjects:navContobj1,navContobj2,navContobj3,navContobj4,navContobj5,nil]];




// use extended method to set background color
//[tab setBackground];
 [self copyDatabaseIfNeeded];
// Override point for customization after application launch.
[self.window addSubview:viewController.view];
[self.window addSubview:tab.view];
[self.window makeKeyAndVisible];
WaaleedKhan
  • 685
  • 7
  • 18