Shrikant K
Shrikant K

Reputation: 2018

UINavigation bar disappearing in iPhone 4 (iOS 7.1.2)

It may be a small issue but I'm not getting where & what is wrong. When I am running on simulator from iPhone 4s to 6+ it's working fine.

enter image description here

But when I am running on iPhone 4 (iOS 7.1.2) the red colored navigation bar disappears.

Here is my code

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

For more details

1) I'm entering into this screen using show segue from previous view.

2) This screen I have made it in storyboard.(I checked constraints too but all constraints are right) I didn't have given any navigation bar in storyboard. Also I have not hidden navigation bar in controller through programatically.

3) I also tried

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

in both viewDidLoad and viewDidAppear but it's not working.

Can anyone please help me out?

After some suggestions i tried updating following code in viewDidLoad, viewDidAppear (with deployment target 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;

Facing same issue.

Upvotes: 1

Views: 108

Answers (1)

Shrikant K
Shrikant K

Reputation: 2018

After spending some more time, i got solution enter image description here

Whenever there is Show segue from one VC to another like above. Then UINavigation bar code

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

is not working for iOS 7.1 (in my case it was happening for Buy voucher second view controller).

So i just removed segue and going through next screen using

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

Then it worked for me & navigation bar is showing for iOS 7.1. :)

Upvotes: 1

Related Questions