2012-03-28 59 views
-1

我是新來的iphone development.Currently我使用標籤式應用程序模板包含4個選項卡,其中一個是有表視圖和單擊表格單元格的項目列表做一個項目,我想給一個說明page.I知道導航必須使用,我成功地提出了導航,但現在的問題是我想在細節頁面的標籤欄也。但在我的它不來。 現在我使用此代碼,以使導航如何在導航中使用標籤欄?

在的appdelegate didfinishlaunching

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動畫:YES];

和對選擇

什麼是做了正確的方法導航? 任何人都可以建議我解決這個問題嗎?

回答

0

有一個在你的代碼或者你的解釋是錯誤的。由於窗口中的第一個視圖是NavigationController的視圖,因此您不構建選項卡式應用。在你的代碼中存在一個危險的東西,因爲窗口上的第一個視圖是navigationcontroller.view,但是rootViewController是tabViewController。不是很聰明。

你想要做什麼是一個選項卡式應用程序具有導航控制器的每個選項卡:

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]; 
+0

感謝它的工作原理下面的代碼... :-) – user1288402 2012-03-28 13:29:23

0

好吧,我所做的是,我有大約5個標籤,每一個爲具有導航控制器

u能custumize

//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]; 
相關問題