【问题标题】:UINavigation bar disappearing in iPhone 4 (iOS 7.1.2)UINavigation 栏在 iPhone 4 (iOS 7.1.2) 中消失
【发布时间】:2015-11-26 10:40:18
【问题描述】:

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

但是当我在 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 进入此屏幕。

2)这个屏幕是我在故事板中制作的。(我也检查了约束,但所有约束都是正确的)我没有在故事板中提供任何导航栏。我也没有通过编程隐藏控制器中的导航栏。

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;

面临同样的问题。

【问题讨论】:

  • 您的 iOS 部署目标是什么?
  • 您现在可以检查的一件事是半透明属性。由于在 iOS7 中所有控制器的半透明属性值为 YES,请尝试将导航栏的半透明属性设置为 NO,看看是否可以解决您的问题。
  • 我的部署目标是 7.0,我尝试添加 self.navigationController.navigationBar.translucent = NO;在 viewDidLoad、viewDidAppear 中。还是不行。
  • 试着把它放在你的 viewDidLoad 中:if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) self.edgesForExtendedLayout = UIRectEdgeNone;
  • 不!会是什么原因?它仅在设备中发生。在所有模拟器中,它都运行良好,为什么会这样?

标签: ios objective-c uinavigationcontroller storyboard uinavigationbar


【解决方案1】:

花了一些时间后,我得到了解决方案

只要像上面那样从一个 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(在我的情况下,它发生在购买凭证第二个视图控制器)。

所以我刚刚删除了 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。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-08
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2013-09-30
    相关资源
    最近更新 更多