Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将选项卡栏和导航栏添加到应用程序_Ios_Uinavigationcontroller_Uitabbarcontroller_Uinavigationbar_Uitabbar - Fatal编程技术网

Ios 将选项卡栏和导航栏添加到应用程序

Ios 将选项卡栏和导航栏添加到应用程序,ios,uinavigationcontroller,uitabbarcontroller,uinavigationbar,uitabbar,Ios,Uinavigationcontroller,Uitabbarcontroller,Uinavigationbar,Uitabbar,我是iOS开发新手。我附加了一个链接到我的项目,希望有人能帮助我这一点。我需要添加一个包含四个项目的选项卡栏(主页、关于我们、联系我们,以及指向将在safari中打开的网站的链接)。除了几个例外,每个视图上都会显示相同的三个项目。“主页”屏幕不需要主页项目,“关于我们”页面不需要该项目,“联系我们”也不需要该项目 我还希望有一个导航栏,将有一个后退按钮上的每个视图,并显示该页面的标题 以下是指向我的项目的链接: 提前谢谢 下面的代码将帮助您解决问题 // set up a local nav

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

我还希望有一个导航栏,将有一个后退按钮上的每个视图,并显示该页面的标题

以下是指向我的项目的链接:


提前谢谢

下面的代码将帮助您解决问题

// 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;
//需要这最后一行来显示窗口(和选项卡栏控制器)
[WindowMakeKeyandVisible]

不要将视图控制器直接推到选项卡栏上,而是首先创建一个导航控制器,并使用其特定控制器的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];

我猜所有这些都被添加到KFBAppDelegate.m?我还没有添加。我只是在用它做任何事情之前验证它应该放在哪里。我在问代码应该放在我的项目中的什么地方。我猜是在AppDelegate.m文件中?最初,您的应用程序需要tabbar作为初始方式,然后应该将其放置在AppDelegate.m文件中是否需要详细说明?就像我在帖子里说的,我是iOS新手。