Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6355623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:48:12+00:00 2026-05-24T22:48:12+00:00

This is really weird and I can’t seem to be able to explain that.

  • 0

This is really weird and I can’t seem to be able to explain that. Took me hours to realize that only when I add a UIImageView as a subView to my self.view in the ViewController viewDidLoad then I can set the tint color of my navbar. If I add the UIImageView in the init method – tint color doesnt do anything to my nav bar.

So…

In this case my nav bar is getting the tint color:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];

//NAV BAR COLOR  
self.navigationController.navigationBar.tintColor = [UIColor blueColor];

//ADDING BACKGROUND IMAGE 
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
imgView.image = [UIImage imageNamed:@"aaa.png"];
[self.view addSubview: imgView];
[self.view sendSubviewToBack:imgView];

}

Here it doesnt (just moved the adding of the image to the init method):

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
  //ADDING BACKGROUND IMAGE 
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
imgView.image = [UIImage imageNamed:@"aaa.png"];
[self.view addSubview: imgView];
[self.view sendSubviewToBack:imgView];    }
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];

//NAV BAR COLOR  
self.navigationController.navigationBar.tintColor = [UIColor blueColor];

}

This is how I call this view:

Login *loginViewController = [[Login alloc] initWithNibName:nil bundle:nil];
UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[self presentModalViewController:navCntrl1 animated:YES];

Any idea why? I am soo puzzled…thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:48:13+00:00Added an answer on May 24, 2026 at 10:48 pm

    It’s nothing to do with your image, it’s to do with the way UINavigationControllers are created.

    Here’s your code (with some comments added) :

    // Create the view controller
    Login *loginViewController = [[Login alloc] initWithNibName:nil bundle:nil];
    
    // Create a navigation controller and add it
    UINavigationController *navCntrl1 = [[UINavigationController alloc] initWithRootViewController:loginViewController];
    

    viewDidLoad is called the first time that the ui needs to know about your view controller’s view. If your viewDidLoad method wants the edit a feature of a navigation controller then _your view controller has to be added to the navigation controller before viewDidLoad is called`.

    In your first example, viewDidLoad was called when you added your view controller to a navigation controller (the second line above).

    In your second example, viewDidLoad was called when you said self.view in the initWithNibNamed:bundle: method. Crucially, this is before your view controller knows that it’s going to be added to a navigation controller. Therefore when you say self.navigationController it won’t know which navigation controller you are talking about. It can’t set the tint of something it doesn’t know about yet!

    In your first example, viewDidLoad is called after you have added your view controller to a navigation controller so when you say self.navigationController it knows which navigation controller you are talking about and can set the tint accordingly.

    To test this yourself, put NSLog(@"%@", self.navigationController); in your viewDidLoad method – I bet it outputs nil for the second example 😉


    FYI :

    You should always be doing the first example anyway – it will only create the image when it’s needed and will let you unload the image in cases of low memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain why using comments like this in css cause really weird effects
This is really weird and can't seem to understand it. I have a header
Ok, this one is really weird... I can't show code for it exactly cause
This is a really weird problem that I have been having. When I download
This really, really urks me, so I hope that someone can give me a
I have a really weird issue that I can't figure out with comparing objects
I'm currently having a really weird issue and I can't seem to figure out
This is really weird, hopefully a fresh pair of eyes can help me figure
I have this really simple trouble I can't seem to overcome. I'm trying to
This is really weird, and I cannot see why this is happening. In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.