Ios 在UITableViewControler中,导航栏标题未设置,后退按钮未禁用

Ios 在UITableViewControler中,导航栏标题未设置,后退按钮未禁用,ios,iphone,uinavigationcontroller,Ios,Iphone,Uinavigationcontroller,我正在故事板中使用UITableViewController [self.navigationController setNavigationBarHidden:NO animated:NO]; [self.navigationItem setHidesBackButton:YES animated:YES]; UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithImage:[UIImage

我正在故事板中使用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中工作

我使用故事板创建了一个简单的场景:uinavigation controller->uiviewcontroller->uitableviewController

代码在uiviewcontroller和uitableviewController上都有效

因此,我建议您检查以下事项:

  • 嵌入uinavigationController的uitableviewcontroller
  • 对于Xcode 6,您的segue类型为Show(例如Push),对于旧版本,您的segue类型为Push
  • 检查模拟度量->顶部栏是否有合适的值(我建议所有导航链都使用推断值)
  • 至于标题和栏装饰,我使用这两种方法作为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;
    }
    
    当然,您可以将此代码段用于您的目的,只需修改装饰参数,如颜色或字体名称/大小


    希望这能有所帮助。

    您将此代码放在了什么地方?哪种方法?如果你没有发现问题,可以使用UIViewController并在里面放一个ViewController。这些更改很小,UIViewController将在以后(以我的经验)为您提供更大的灵活性。我将此代码放在viewWillApear方法中。