但我似乎无法将按钮拖到那里,或者在设置标题时,没有任何内容显示出来。如何在Storyboard中实现此设置?
根据下面的答案更新问题。
当我使用这个新的设置(因此在中间添加了一个额外的导航控制器)时,我可以在故事板中设置标题,但是运行应用程序时,添加的标题不会显示。
我已经上传了一个具有完全相同设置的Xcode项目。也许它会有所帮助。
根据下面的答案更新问题。
当我使用这个新的设置(因此在中间添加了一个额外的导航控制器)时,我可以在故事板中设置标题,但是运行应用程序时,添加的标题不会显示。
我已经上传了一个具有完全相同设置的Xcode项目。也许它会有所帮助。
如果您想更改 UINavigationBar
的标题(而不需要创建另外两个 UINavigationController
),您只需使用以下方法:
[self.parentViewController.navigationItem setTitle:@"Title"];
同时,为了添加右侧按钮,请使用以下代码:
self.parentViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(myRightButton)];
在你的UITabBarController
中引用的每个UIViewController
上的viewDidLoad
方法中。
如果您想在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
并显示你自己的。
之后,你就可以使用父级UINavigationController
上的popToRootViewControllerAnimated
: 返回到你的表中。以防有人正在寻找快速方法:
tabBarController?.title = "Your Title"
tabBarController?.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Right Button Title", style: UIBarButtonItemStyle.Plain, target: self, action: "rightButtonFunction")
将代码放在 viewDidAppear
或 viewWillAppear
方法中最佳,这样标题和按钮会随不同的选项卡而改变。
使用这种方法,您也不需要额外的导航控制器。
我看了你的测试应用程序,确实在导航栏下方很模糊地看到了标题。如果选择选项卡栏控制器, 并取消 "在顶部栏下" 的勾选,您就可以看到两个导航栏。但是,这会在导航栏上产生奇怪的阴影。我不知道是否有简单的方法来解决这个问题,但无论如何,我认为拥有两个导航栏的界面看起来并不好。您可能希望消除最初的导航控制器,并使用模式转换器来呈现选项卡栏控制器。您可以将一个栏按钮项目添加到您仍然需要执行模态视图控制器的导航控制器。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"Overview_Register"])
{
WDRegisterViewController *obj=(WDRegisterViewController *)[segue destinationViewController];
obj.str_Title=@"Edit Profile";
obj.isRegister=NO;
}
}
[self performSegueWithIdentifier:@"Overview_Measure" sender:nil];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
WDPeekViewController *Peek = (WDPeekViewController *)[sb instantiateViewControllerWithIdentifier:@"WDPeekViewController"];
[self.navigationController pushViewController:tabBarController animated:YES];
你需要用UINavigationViewControllers
替换那些视图控制器。
删除右边的两个视图控制器。
将2个UINavigationViewControllers
拖放到故事板上,并按照您想要的位置放置它们。
然后,您需要将这些新的导航视图控制器连接到选项卡栏控制器。从选项卡栏控制器向导航控制器进行Ctrl单击并拖动。从弹出的菜单中选择“关系Segue”部分的“视图控制器”。对于两个导航控制器都要这样做。
[[self tabBarController] setTitle:@"First View Controller"];
。虽然有点不规范,但它能够正常工作。 - ColdLogic