简体   繁体   English

在UITableViewControler中未设置导航栏标题和后退按钮

[英]Navigation bar Title not set and back button not disable in UITableViewControler

I am using UITableViewController in storyboard. 我在情节提要中使用UITableViewController。

    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [self.navigationItem setHidesBackButton:YES animated:YES];

    UIBarButtonItem *editButton = [[UIBarButtonItem alloc]   initWithImage:[UIImage imageNamed:@"back2.png"] style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    self.navigationItem.leftBarButtonItem = editButton;

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];

    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:(44/255.0f) green:(165/255.0f) blue:(264/255.0f) alpha:(1.0f)]];

    [self.navigationItem setTitle:@"SETTINGS"];

    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

The problem is i want to hide Back button and title are not show in navigation bar. 问题是我想隐藏“后退”按钮,标题不显示在导航栏中。 same code works in UIViewcontroller. 相同的代码可在UIViewcontroller中使用。

I created simple scene using storyboard: uinavigation controller -> uiviewcontroller -> uitableviewController. 我使用情节提要板创建了简单的场景:uinavigation控制器-> uiviewcontroller-> uitableviewController。

Code works on both uiviewcontroller and uitableviewController. 代码可在uiviewcontroller和uitableviewController上运行。

So, i suggest you to check the next things: 因此,我建议您检查以下内容:

  1. your uitableviewcontroller embeded with uinavigationController; 您的uitableviewcontroller嵌入了uinavigationController;
  2. your segue type is Show (eg Push) for Xcode 6 or Push for older versions 您的Segue类型对于Xcode 6是Show(例如Push),对于较旧的版本是Push
  3. Check simulated metrics -> Top bar for proper value (i recommend Inferred for all navigation chain) 检查模拟指标->顶部栏的值是否正确(我建议为所有导航链推断)

As for title and bar decoration i used this two methods as a category for UIViewController to split decoration logic from title logic 至于标题和栏装饰,我将这两种方法用作UIViewController的类别,以将装饰逻辑与标题逻辑分开

-(void)decorateNavigationBarAppearance
{   
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                                  forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.view.backgroundColor = [UIColor clearColor];
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
    self.navigationController.navigationBar.tintColor = RGB(255, 255, 255);
    self.navigationController.navigationBar.shadowImage = [self imageWithColor:RGB(154, 153, 163) size:(CGSizeMake(self.view.frame.size.width, 1.0f))];    
}

- (void) setNavigationItemTitle:(NSString *)title
{

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 310, 40)];
    titleLabel.text = title;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.font = [UIFont fontWithName:@"ProximaNova-Bold" size:17];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textColor = RGB(255, 255, 255);
    UIView *content = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
    [content addSubview:titleLabel];
    self.navigationItem.titleView = content;
}

Sure, you can use this snippet for you purpose just modifying decoration params such colour or font name/ size 当然,您可以仅出于修改装饰参数(例如颜色或字体名称/大小)的目的使用此代码段

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM