gho*_*der 13 titlebar uitabbarcontroller uinavigationcontroller ios
在我的应用程序中,我有一个带有表格视图的导航控制器,当按下按钮时,一个标签控制器打开.在第一个选项卡中,我想要设置导航栏的标题.
这是我的故事板的图像,只是为了确保我们彼此不相符.

这是我应该工作的代码.当我尝试打开单个视图而不是选项卡控制器并且它正常工作时,我使用了这段代码.所以我想我必须改变一些事情.
- (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;
}
Run Code Online (Sandbox Code Playgroud)
Skicenter我的第一个选项卡的类名称在哪里,是SkiCenterIds故事板中我的选项卡控制器的标识符.
Skicenter.m中的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.navigationItem.title = ski_center;
}
Run Code Online (Sandbox Code Playgroud)
但我没有看到任何头衔.那我做错了什么?我也试过这个:
[self.navigationController setTitle:@"Live"];
Run Code Online (Sandbox Code Playgroud)
要么
self.title=ski_center;
Run Code Online (Sandbox Code Playgroud)
ski_center具有价值,因为它在NSLog中正常打印出来.
nit*_*ddy 40
简单!
[self.tabBarController setTitle:@"Title"];
Run Code Online (Sandbox Code Playgroud)
小智 16
添加到ghostrider的解决方案,在mytabbarcontroller.m中,self.navigationItem.title对我不起作用.我有一个NavigationController,其详细视图是一个TabController,这是我在第一个tab实现中的内容
self.navigationController.visibleViewController.title = ski_center;
Run Code Online (Sandbox Code Playgroud)
在迅捷 3
self.tabBarController?.navigationItem.title = "Your title goes here"
Run Code Online (Sandbox Code Playgroud)
好的,所以你知道,这是一个非常糟糕的做法,UITabBarController内置一个UINavigationController- 苹果推荐良好的用户界面设计,你只应该放在一个UINavigationController内部UITabBarController而不是相反的方式.无论哪种方式,你都应该能够改变这样的标题UITabBarController;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[self.navigationController.viewControllers objectAtIndex:0] setTitle:ski_center];
}
Run Code Online (Sandbox Code Playgroud)
这应该工作.
我遇到了这个并找到了一个更简单的解决方案。一个新的解决方案是从着陆视图控制器更改导航栏标题,如下所示
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.topItem?.title = "title";
}
Run Code Online (Sandbox Code Playgroud)
基本上我不知道你是否注意到,但我的工作原理是这样的:
我为我的标签栏控制器分配了一个新类。
我做了以下事情:
将其添加到应用程序 delegate.h
@property (nonatomic,retain) NSString *center;
Run Code Online (Sandbox Code Playgroud)
将其添加到mainmap.m
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
delegate.center=[centers objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)
和mytabbarcontroller.m中
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
ski_center=delegate.center;
self.navigationItem.title = ski_center;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18076 次 |
| 最近记录: |