我是否需要嵌入UINavigationController&以编程方式添加UINavigationBar?

时间:2015-07-21 18:47:47

标签: ios xcode storyboard

我没有看到我的所有导航栏。 导航栏的位置只有一个轮廓。 我设置了navigationBar Color和tint颜色,以便定义此导航栏,即使它没有项目。

  1. 我使用Storyboard制作当前功能性的UI。
  2. 我的故事板UI包括代表,自定义集合视图单元格,自定义表格视图单元格和动画。

  3. 在我的应用程序结束时,我想以编程方式向每个ViewControllers添加导航栏。 (见代码)

  4. 我在其他6个类中使用过此代码。而且我在那些ViewControllers中有6个完美无瑕的导航栏。

    - (void)viewDidLoad
    {
      [super viewDidLoad];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizeralloc] 
       initWithTarget:self 
       action:@selector(titleGestureLabelMethod)];
    
        UILabel * titleView = [UILabel new];
              titleView.text = @"Title";
            titleView.textColor = [UIColor greenColor];
            [titleView sizeToFit];
            titleView.userInteractionEnabled = YES;
            [titleView addGestureRecognizer:tapGesture];
    
             self.navigationItem.titleView = titleView; 
             [self.view addSubview:titleView]; 
             [self.navigationController.navigationBar   setTranslucent:NO]; 
    
    UIBarButtonItem *lButton = [[UIBarButtonItem alloc] initWithTitle:@"L"
     style:UIBarButtonItemStylePlain
     target:sel
     action:@selector(lButtonMethod)];
    
    [self.navigationItem setLeftBarButtonItem:lButton animated:YES];
    
    UIBarButtonItem *rButton = [[UIBarButtonItem alloc]
                                      initWithTitle:@"R"
                                      style:UIBarButtonItemStylePlain
                                      target:self
                                      action:@selector(rButtonMethod)];
    
     [self.navigationItem setRightBarButtonItem:rButton animated:YES];
    
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    [self.navigationController.navigationBar setBarTintColor:[UIColor    greenColor]];
    
     [self.view addSubview:testTwoNavBar];
    
    
    }
    

1 个答案:

答案 0 :(得分:0)

您需要将视图控制器嵌入导航控制器中。如果您正在使用Interface Builder,请从故事板中选择视图控制器。在菜单中选择编辑器并选择嵌入导航控制器。从这个问题来看,你很难理解你真正需要什么。

相关问题