【发布时间】:2026-01-20 04:35:02
【问题描述】:
在我的应用程序中,我有一个带有表格视图的导航控制器,当按下按钮时,一个选项卡控制器会打开。在它的第一个选项卡中,我希望设置导航栏的标题。
这是我的故事板的图像,只是为了确保我们彼此不了解。
这是我应该可以工作的代码。我在尝试打开单个视图而不是选项卡控制器时使用了此代码,并且它工作正常。所以我想我必须改变一些东西。
- (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 是我在情节提要中的选项卡控制器的标识符。
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 之所以有价值,是因为它在 NSLog 中正常打印出来。
【问题讨论】:
-
您是否在导航控制器中使用标签栏控制器?
标签: ios uinavigationcontroller uitabbarcontroller titlebar