在我的应用程序中,我有一个带有表格 View 的导航 Controller ,当按下按钮时,一个选项卡 Controller 会打开。在它的第一个选项卡中,我想设置导航栏的标题。
这是我的 Storyboard图片,以确保我们相互理解。
这是我的代码,应该可以正常工作。我在尝试打开单个 View 而不是选项卡 Controller 时使用了这段代码,并且它工作正常。所以我想我必须改变一些东西。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SkiCenter *myDetViewCont = [[SkiCenter alloc] initWithNibName:@"SkiCenter" bundle:[NSBundle mainBundle]];
myDetViewCont.ski_center = [centers objectAtIndex:indexPath.row];
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
[[self navigationController] pushViewController:[storyBoard instantiateViewControllerWithIdentifier:@"SkiCenterIds"] animated:YES];
//[self.navigationController pushViewController:myDetViewCont animated:YES]; // "Pushing the controller on the screen"
[myDetViewCont release]; // releasing controller from the memory
myDetViewCont = nil;
}
Skicenter
是我的第一个选项卡的类名,SkiCenterIds
是 Storyboard中我的选项卡 Controller 的标识符。
Skicenter
.m 中的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationItem.title = ski_center;
}
但是我没有看到任何标题。那么我做错了什么? 我也试过这个:
[self.navigationController setTitle:@"Live"];
或
self.title=ski_center;
ski_center 是有值(value)的,因为它在 NSLog 中正常打印出来。
最佳答案
简单!
[self.tabBarController setTitle:@"Title"];
关于ios - 在标签栏 Controller 中设置导航栏的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12329895/