ios - 导航栏在 iPhone 4 (iOS 7.1.2) 中消失

标签 ios objective-c uinavigationcontroller storyboard uinavigationbar

这可能是一个小问题,但我不知道哪里出了问题。 当我在 iPhone 4s 到 6+ 的模拟器上运行时,它工作正常。

enter image description here

但是当我在 iPhone 4 (iOS 7.1.2) 上运行时,红色导航栏消失了。

这是我的代码

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
// Override point for customization after application launch.
  [[UINavigationBar appearance]setBarTintColor:[UIColor redColor]];
 }

更多详情

1) 我正在使用 show segue from previous view 进入这个屏幕。

2) 这个屏幕是我在 Storyboard 中制作的。(我也检查了约束,但所有约束都是正确的)我没有在 Storyboard 中给出任何导航栏。此外,我没有通过编程方式在 Controller 中隐藏导航栏。

3)我也试过了

//    UINavigationBar *navbar = [[UINavigationBar   alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
//    [navbar setBackgroundColor:[UIColor yellowColor]];
//    [self.view addSubview:navbar];

在 viewDidLoad 和 viewDidAppear 中,但它不工作。

谁能帮帮我?

根据一些建议,我尝试更新 viewDidLoad、viewDidAppear 中的以下代码(部署目标为 7.1)

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
 {
    self.edgesForExtendedLayout = UIRectEdgeNone;
 }


    UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 55)];
    [navbar setBackgroundColor:[UIColor yellowColor]];

self.navigationController.navigationBar.translucent = NO;

[self.view addSubview:navbar];

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 19, 20)];
    [button addTarget:self action:@selector(didTapBackBtn:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal];
    UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = backBarButton;

面临同样的问题。

最佳答案

花了更多时间后,我得到了解决方案 enter image description here

每当有从一个 VC 到另一个 VC 的 Show segue 时,就像上面那样。然后是UINavigation条码

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
 // Override point for customization after application launch.
 [[UINavigationBar appearance]setBarTintColor:[UIColor redColor]];
 }

不适用于 iOS 7.1(在我的例子中,它发生在 Buy voucher 第二个 View Controller 上)。

所以我只是删除了 segue 并使用了下一个屏幕

- (IBAction)didTapOnNext:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
BuyVaucherSecondViewController *bvs = [storyboard instantiateViewControllerWithIdentifier:@"buyVaucherSecond"];
[self.navigationController pushViewController:bvs animated:YES];
}

然后它对我有用,导航栏显示为 iOS 7.1。 :)

关于ios - 导航栏在 iPhone 4 (iOS 7.1.2) 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32327453/

相关文章:

ios - 项目上有白色背景的 UIDatePicker

ios - 构建 Ios 应用程序以跟踪建筑物内设备的确切位置

iphone - NSMutableArray : Memory management while calling methods

ios - 关闭 View Controller 意外行为

ios - 连接到自定义类时单元格消失

swift - SwiftUI 中的推送、弹出 View Controller 等效项

ios - Xcode 4.5 背景图像 iPhone 4、4s、5

ios - 使用外观代理或 self.view.tintColor 设置 tintColor?

ios - 显示键盘时如何决定滚动哪个 UIScrollView

ios - NSString stringWithCString不显示特殊字符吗?