Objective c 停留在TabBarController上方的导航栏
我想有一个导航栏,上面有一个设置按钮,无论它在哪个选项卡上,它都会保持在那里 对不起,我发短信迟到了Objective c 停留在TabBarController上方的导航栏,objective-c,uitabbarcontroller,uinavigationbar,Objective C,Uitabbarcontroller,Uinavigationbar,我想有一个导航栏,上面有一个设置按钮,无论它在哪个选项卡上,它都会保持在那里 对不起,我发短信迟到了 Chase您可以做的是将UIToolBar拖到情节提要控制器上,然后在那里设置所需的按钮和操作。您可以使所有的控制器从相同的基类扩展而不必重复代码,如果您觉得这个工具栏更令人愉快,还可以用代码实例化它 问题在于使用导航时,导航栏将替换/重叠此工具栏 UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, s
Chase您可以做的是将UIToolBar拖到情节提要控制器上,然后在那里设置所需的按钮和操作。您可以使所有的控制器从相同的基类扩展而不必重复代码,如果您觉得这个工具栏更令人愉快,还可以用代码实例化它 问题在于使用导航时,导航栏将替换/重叠此工具栏
UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithTitle:@"Title"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(myAction:)];
[myToolbar setItems:[NSArray arrayWithObjects:myButton, nil]];
[self.view addSubview:myToolbar];
在AppDidFinishLaunching中:
Add Your TabBarcontroller (rootViewController) for UINavigationController
下面的添加设置按钮是navigationBar中的示例
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonSystemItemDone target:nil action:nil];
navigationCOntroller.navigationItem.rightBarButtonItem = rightButton
rightButton将通过应用程序可见如果您只想放置一个带有设置按钮的导航栏,该按钮可以使用UITabBarController从任何视图访问,您可以在AppDelegate中执行类似操作--> 在所有视图上都应该有一个带有导航栏的选项卡栏。现在要在导航栏中放置设置按钮,请将其添加到视图控制器中要显示设置按钮-->
我不需要使用导航。我只是想要一个地方来放置设置按钮,它看起来很漂亮,可以从任何选项卡访问。如果这样的话,我提出的解决方案将不会出现问题,请尝试一下,让我知道。我用一个小代码编辑了我的答案,同样可以在interface builder中完成,并用控件拖动将其连接起来
YourViewController1 *yourVC1 = [YourViewController1 alloc] initWithNibName:@"YourViewController1" bundle:nil];
UINavigationController *yourNVC1 = [[UINavigationController alloc] initWithRootViewController:yourVC1];
YourViewController2 *yourVC2 = [YourViewController2 alloc] initWithNibName:@"YourViewController2" bundle:nil];
UINavigationController *yourNVC2 = [[UINavigationController alloc] initWithRootViewController:yourVC2];
UITabBarController *tabBC = [[UITabBarController alloc] init];
[tabBC setViewControllers:[NSArray arrayWithObjects:yourNVC1, yourNVC2, nil]];
self.window.rootViewController = tabBC;
UIBarButtonItem *selectBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(selectorName:)];
self.navigationItem.rightBarButtonItem = selectBarButton;