0

我是 iOS 开发的新手。我附上了我的项目的链接,希望有人可以帮助我。我需要添加一个包含四个项目的标签栏(主页、关于我们、联系我们,以及指向将在 safari 中打开的网站的链接)。除了几个例外,每个视图上都会出现相同的三个项目。“主页”屏幕不需要主页项目,关于我们页面不需要那个项目,联系我们也不需要那个项目。

我还想要一个导航栏,在每个视图上都有一个后退按钮并显示该页面的标题。

这是我的项目的链接: https ://www.dropbox.com/s/sv0y3oh1aftxl95/KFBNewsroom%204.zip

提前致谢!

4

2 回答 2

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;

// 需要最后一行来显示窗口(和标签栏控制器) [window makeKeyAndVisible];

于 2012-11-02T13:43:29.377 回答
0

与其将视图控制器直接推送到标签栏上,不如先创建一个导航控制器并使用其特定控制器的 rootviewcontroller 对其进行初始化

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];
于 2012-11-02T13:51:48.920 回答