Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 以编程方式切换到其他选项卡不会更改导航栏标题_Ios_Objective C_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Ios 以编程方式切换到其他选项卡不会更改导航栏标题

Ios 以编程方式切换到其他选项卡不会更改导航栏标题,ios,objective-c,uinavigationcontroller,uitabbarcontroller,Ios,Objective C,Uinavigationcontroller,Uitabbarcontroller,我在NavController中嵌入了一个Tabbar控制器。My TabBarController ViewDidAspect方法调用此方法以根据TabBarItem.tag设置导航栏: -(void)updateNaviationWithTabBarItem:(UITabBarItem *)item{ if(item.tag == 1){ self.title = @"Live Feed"; NSLog(@"live"); [self.navigationContro

我在NavController中嵌入了一个Tabbar控制器。My TabBarController ViewDidAspect方法调用此方法以根据TabBarItem.tag设置导航栏:

-(void)updateNaviationWithTabBarItem:(UITabBarItem *)item{
if(item.tag == 1){
    self.title = @"Live Feed";
    NSLog(@"live");
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor], NSFontAttributeName:[UIFont fontWithName:@"Helvetica Neue" size:22]}];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:.4];
    [self.button  setTintColor:[UIColor colorWithRed:0.41 green:0.68 blue:0.9 alpha:1]];
}else if (item.tag == 2){
    self.title = @"Camera";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont fontWithName:@"Helvetica Neue" size:22]}];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.41 green:0.68 blue:0.9 alpha:.4];
    [self.button  setTintColor:[UIColor whiteColor]];
}
用户从CameraViewController上载图片后,选项卡将以编程方式更改,如下所示:

-(void)presentFeedView {
FeedTableViewController *feedVC = self.tabBarController.viewControllers[0];
[self.tabBarController setSelectedViewController:feedVC];}
当我到达选项卡时,导航栏将保留上一个ViewController中的设置。在其他选项卡中也会发生这种情况

在检查tabBarItem.tag后是否应该转换到选项卡? 我应该从其他地方调用此方法吗


编辑:从日志语句中可以看出,该方法被调用了一次,并且仅在最初加载视图时调用一次。

切换选项卡时,您需要在视图控制器中手动更改它。通常它在视图中会出现,但我不确定当您切换选项卡时是否会触发,但这是您需要调用的代码

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    [self setTitle:@"A"];
    self.tabBarController.navigationItem.title = @"A";
}
不过你可能需要把它放在这里

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    //change the title based on viewController that is selected
    self.title = @"New title";
}

这可能会帮助您self.navigationController.navigationBar.topItem.title=@“您的标题”文本;为什么不调试代码并检查控制是否进入if block或else block…我应该提到。我有三个VC,它们是FeedViewController的子类,所以我需要检查选项卡索引或标签,保存数据,并通过控制器id或其他方式对其进行索引。您可以让每个人实现该方法,以便在调用该方法时正确显示正确的标题。