我正在尝试在 Storyboard 中进行以下设置。
我一开始有一个表格 View ,当我点击一个单元格时,它需要转换到标签栏 Controller ,这是可行的。但是现在我想要在最右边的两个 Controller 中有一个标题和一个额外的导航栏按钮。
但我似乎无法将按钮拖到那里,或者在设置标题时,什么也没有显示。如何在 Storyboard 中实现此设置?
根据以下答案更新了问题。
当我有了这个新设置(因此中间有一个额外的导航 Controller )时,我可以在 Storyboard 中设置标题,但是在运行应用程序时,添加的标题不会显示。
我有uploaded具有完全相同设置的 Xcode 项目。也许它能派上用场。
最佳答案
要更改 UINavigationBar
标题(无需创建其他 2 个 UINavigationController
),您只需使用
[self.parentViewController.navigationItem setTitle:@"Title"];
添加右键使用
self.parentViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(myRightButton)];
在 viewDidLoad
方法上为从您的 UITabBarController
引用的每个 UIViewController
。
如果您想在 TabItems
的 UIViewController
中使用“导航结构”,那么您可以将 BUFViewController.m 编辑为:
#import "BUFViewController.h"
@interface BUFViewController ()
@end
@implementation BUFViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.parentViewController.navigationController setNavigationBarHidden:YES];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
}
-(void)done{
[self.parentViewController.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
您必须认为您的 UITabBarController
位于您的父级 NavigationController
中,因此您想隐藏父级 UINavigationBar
并显示您的父级。
之后,您将能够使用 popToRootViewControllerAnimated
返回您的表格:在父级的 UINavigationController
上。
希望对您有所帮助:)
关于ios - Storyboard导航 Controller 和标签栏 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23548088/