ios - 在标签栏 Controller 中设置导航栏的标题

标签 ios uinavigationcontroller uitabbarcontroller titlebar

在我的应用程序中,我有一个带有表格 View 的导航 Controller ,当按下按钮时,一个选项卡 Controller 会打开。在它的第一个选项卡中,我想设置导航栏的标题。

这是我的 Storyboard图片,以确保我们相互理解。

enter image description here

这是我的代码,应该可以正常工作。我在尝试打开单个 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/

相关文章:

ios - 添加一个 UIButton 到 RootViewController 的 navigationBar

ios - 电话号码格式应该是国际格式,iPhone 中是否有用于电话号码验证的正则表达式

ios - 如何裁剪 UIScrollView 中显示的 UIImageView 部分并将其保存到 UIImage 变量?

ios - 阻止 CALayer 阴影影响 subview ?

ios - 在导航栏中按下后退按钮时刷新 RootViewController 的内容

ios - 如何回到第一 View

swift - 返回索引为 2 的标签栏 Controller

ios - 当 vc 弹出时,在选项卡栏下显示的 UITabBar 上添加 subview

ios - 如何使用 CrossDissolve 幻灯片过渡动画标签栏选项卡切换?

ios - 从具有不同过渡动画的 UIImage 数组制作视频