0

我是iOS開發新手。我附上了一個鏈接到我的項目,希望有人可以幫助我。我需要添加一個帶有四個項目的標籤欄(主頁,關於我們,與我們聯繫,並鏈接到將在safari中打開的網站)。除了兩個例外情況外,每個視圖都有相同的三項。 「家」屏幕將不需要家庭物品,關於我們的頁面將不需要該物品,並且聯繫我們將不需要該物品。將標籤欄和導航欄添加到應用程序

我還想要一個導航欄,每個視圖上都有一個後退按鈕並顯示該頁面的標題。

這裏是鏈接到我的項目: https://www.dropbox.com/s/sv0y3oh1aftxl95/KFBNewsroom%204.zip

提前感謝!

回答

0

下面的代碼將幫助您解決問題

// set up a local nav controller which we will reuse for each view controller 
UINavigationController *localNavigationController; 

// create tab bar controller and array to hold the view controllers 
UITabBarController *tabBarController = [[UITabBarController alloc] init]; 

NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:1]; 

// setup the first view controller (Root view controller) 
RootViewController *myViewController; 
myViewController = [[RootViewController alloc] initWithTabBar]; 

// create the nav controller and add the root view controller as its first view 
localNavigationController = [[UINavigationController alloc] initWithRootViewController:myViewController]; 
localNavigationController.navigationBar.barStyle = UIBarStyleBlack; 
localNavigationController.delegate = self; 

[localControllersArray addObject:localNavigationController]; 

// release since we are done with this for now 
[localNavigationController release]; 
[myViewController release]; 

tabBarController.viewControllers = localControllersArray; 
tabBarController.moreNavigationController.navigationBar.barStyle = UIBarStyleBlack; 

tabBarController.delegate = self; 
tabBarController.moreNavigationController.delegate = self; 

// release the array because the tab bar controller now has it 
[localControllersArray release]; 

self.tabBarController.selectedIndex = 0; 

// add the tabBarController as a subview in the window 
self.window.rootiviewcontroller = self.tabbarcontroller; 

//需要這最後一行顯示的窗口(和標籤欄控制器) [窗口makeKeyAndVisible]

+0

我猜這一切被添加到KFBAppDelegate.m的RootViewController的初始化呢? – RagingGoat

+0

添加此代碼時會出現什麼問題 – Vinodh

+0

我還沒有添加。在我做任何事情之前,我只是驗證它需要去哪裏。 – RagingGoat

0

,而不是直接推視圖控制器到TabBar,所以首先創建一個導航控制器,並用其特定的控制器

Settings *settingsVC = [[Settings alloc] init]; 
UINavigationController *settingsNavigationController = [[UINavigationController alloc] initWithRootViewController:settingsVC]; 
Report *reportVC = [[Report alloc] init]; 
UINavigationController *reportNavigationController = [[UINavigationController alloc] initWithRootViewController:reportVC]; 
Episodes *episodesVC = [[Episodes alloc] init ]; 
UINavigationController *episodesNavigationController = [[UINavigationController alloc] initWithRootViewController:episodesVC]; 
UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeVC]; 

NSArray* controllers = [[NSArray alloc] initWithObjects:settingsNavigationController, 
           reportNavigationController, 
           episodesNavigationController, 
           homeNavigationController, nil];