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 7179783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:12:40+00:00 2026-05-28T17:12:40+00:00

I have my current base sdk set to iOS 4.2. I have this method:

  • 0

I have my current base sdk set to iOS 4.2.
I have this method:

    - (void) setNavigationBarBackground
    {
    if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
        //iOS 5.0
        if ([self respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)])
        {
            [self setBackgroundImage:[UIImage imageNamed:kImageNavBar] forBarMetrics:UIBarMetricsDefault];
        }
    }
    else
    {
        //iOS 4.whatever and below
        UIImageView *imageView = (UIImageView *)[self viewWithTag:kNavigationBarBackgroundImageTag];
        if (imageView == nil)
        {
            imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kImageNavBar]];
            [imageView setTag:kNavigationBarBackgroundImageTag];
            [self insertSubview:imageView atIndex:0];
            [imageView release];
        }
    }
}

When I build my project, i encounter a compile-time error as:

'UIBarMetrics' Default undeclared (first use in this function)

When I set my base sdk to 5.0, it compiles without any error.

Does anybody know how can I compile it using base sdk 4.2?

  • 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-28T17:12:40+00:00Added an answer on May 28, 2026 at 5:12 pm

    for specifically your case, use this:

    #if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
    if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TitleBar"] forBarMetrics:UIBarMetricsDefault];
    }
    #endif
    

    In general, a good way to conditionally compile across various SDK versions is this:

    put this at the top (along with imports):

    #define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
    #define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
    #define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
    

    then if there are some OS specific features, use them like this (I am using AlertView as an example. Pre iOS5, UIAlertView does not support a custom textView inside it, so I had my own custom AlertView. In iOS5, that hack does not work and I have to use UIAlertView as it supports custom textViews):

    if (SYSTEM_VERSION_LESS_THAN(@"5.0")) {
    
    TextAlertView *alert = [[TextAlertView alloc] initWithTitle:@"xxxYYzz" 
                                                        message:@"" 
                                                       delegate:self cancelButtonTitle:@"Add"
                                              otherButtonTitles:@"Cancel", nil];
    alert.textField.keyboardType = UIKeyboardTypeDefault;
    alert.tag = 1;
    self.recipeNameTextField = alert.textField;
    [alert show];
    [alert release];
    }
    else {
         UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"xxYYzz"
                                               message:@"" 
                                               delegate:self cancelButtonTitle:@"Add"
                                      otherButtonTitles:@"Cancel", nil];
         alert.alertViewStyle = UIAlertViewStylePlainTextInput;
         self.recipeNameTextField = [alert textFieldAtIndex:0];
    
         [alert show];
         [alert release];
     }
    

    Hope it helps

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

Sidebar

Related Questions

My application builds and runs fine on 10.6. I have Base SDK set to
The current class library I am working on will have a base class (Field)
I have three current thoughts on how to do this: re-implement AuthenticationService, which uses
As a beginner in Ocaml, I have this current working code: ... let ch_in
Can anyone help me getting started with this? We have a current keygen for
I'm looking for the best method for the following issue I have. I current
I have a base class that I want to look like this: class B
I have a Base Class, called primitive Graphics. derived from this class are several
I have a base controller abstract class, which my other controllers inherit. This class
I have a Screen base class from which all other Screens extend. Within this

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.