【问题标题】:Navigation bar Title not set and back button not disable in UITableViewControlerUITableViewControler 中未设置导航栏标题和未禁用后退按钮
【发布时间】:2015-06-22 12:35:31
【问题描述】:

我在情节提要中使用 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];

问题是我想隐藏后退按钮和标题不显示在导航栏中。相同的代码适用于 UIViewcontroller。

【问题讨论】:

  • 你把这段代码放在哪里了?用什么方法?
  • 如果你没有发现问题,也许只是使用一个UIViewController并在里面放一个ViewController。更改很小,UIViewController 稍后会为您提供更大的灵活性(根据我的经验..)
  • 我把这段代码放在 viewWillApear 方法中。

标签: ios iphone uinavigationcontroller


【解决方案1】:

我使用情节提要创建了简单的场景:uinavigation 控制器 -> uiviewcontroller -> uitableviewController。

代码适用于 uiviewcontroller 和 uitableviewController。

所以,我建议你检查接下来的事情:

  1. 您的 uitableviewcontroller 嵌入了 uinavigationController;
  2. 您的 segue 类型是 Xcode 6 的 Show(例如 Push)或旧版本的 Push
  3. 检查模拟指标 -> 顶部栏的正确值(我建议对所有导航链进行推断)

关于标题和条形装饰,我使用这两种方法作为 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;
}

当然,您可以使用这个 sn-p 来修改装饰参数,例如颜色或字体名称/大小

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多