tabBarItem与NavigationBar的title

今天在调试时发现,tabBarItem的title与NavigtionBar的title存在一定的关联。
当在控制中执行self.title = @"xxxx";或执行xxxVc.title = @"xxxx" 会同时将tabBarItem与Navigation的title同时赋值为xxxx.

代码如下:


//设置tabar视图

- (void)viewDidLoad {
    [super viewDidLoad];

    MeViewController *me = [[MeViewController alloc] init]; //创建视图控制器

  //将me添加到当前视图控制器中
    [self addChildVc:me
               title:@"与我相关"
               image:[UIImage imageNamed:@"tabbar_icon_at"]
       selectedImage:[UIImage imageNamed:@"tabbar_icon_at_click"]];
    
}

- (void)addChildVc:(UIViewController *)childVc
             title:(NSString *)text
             image:(UIImage *)image
     selectedImage:(UIImage *)selectedImage{
    
    childVc.tabBarItem = [childVc.tabBarItem initWithTitle:nil  //此处为nil
                                                     image:image
                                             selectedImage:selectedImage];
    
    childVc.title = text;  

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    
    [self addChildViewController:nav]; //向子视图中添加控制器
}

效果图:

你可能感兴趣的:(tabBarItem与NavigationBar的title)