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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:43:53+00:00 2026-05-18T04:43:53+00:00

I wish the first time anyone loads my application to have it start at

  • 0

I wish the first time anyone loads my application to have it start at the preferences view i have and every other time to start at the main view.

I could not find a way to detect if this is the first time the application is run. any ideas?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch
    NSUserDefaults      *padFactoids;
    int                 launchCount;

    padFactoids = [NSUserDefaults standardUserDefaults];
    launchCount = [padFactoids integerForKey:@"launchCount" ] + 1;
    [padFactoids synchronize];

    NSLog(@"this is the number: %i of times this app has been launched", launchCount);
        if ( launchCount == 1 )
    {
        NSLog(@"this is the FIRST LAUNCH of the app");
        // do stuff here as you wish
        bbb = [[Blue alloc]init];
        [window addSubview:bbb.view];
    }
    if ( launchCount >= 2 )
    {
        NSLog(@"this is the SECOND launch of the damn app");
        // do stuff here as you wish
        rrr = [[Red alloc]init];
        [window addSubview:rrr.view];
    }
    [window makeKeyAndVisible];

    return YES;
}

here Red & Blue are subclasses of uiviewcontroller in both classes only one difference is that in -(void)viewDidLoad{
self.view.backgroundcolor = [UIColor redColor];
}in case of Red class & in blue class which shows blue backgroundcolor
but when i execute app its shows only blue color not show red color where i wrong what i do for when i ran app IInd time it shows red color…..

  • 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-18T04:43:53+00:00Added an answer on May 18, 2026 at 4:43 am

    Here is exactly how to do it. You will be pleased to know it is incredibly easy. It is exactly FOUR lines of code.

    Add this code anywhere you want. Perhaps simply in your application:didFinishLaunchingWithOptions: routine in the file AppDelegate.m. Or, wherever you do general setup for your application. (However, be sure it will run once only.)

    NSUserDefaults      *padFactoids;
    int                 launchCount;
    
    padFactoids = [NSUserDefaults standardUserDefaults];
    launchCount = [padFactoids integerForKey:@"launchCount" ] + 1;
    [padFactoids setInteger:launchCount forKey:@"launchCount"];
    [padFactoids synchronize];
    
    NSLog(@"number of times: %i this app has been launched", launchCount);
    
    if ( launchCount == 1 )
        {
        NSLog(@"this is the FIRST LAUNCH of the app");
        // do stuff here as you wish
        }
    if ( launchCount == 2 )
        {
        NSLog(@"this is the SECOND launch of the damn app");
        // do stuff here as you wish
        }
    
    // enjoy!
    

    Almost every app, other than the simplest, does this. Hope it helps. For the record in theory you do not necessarily have to bother with the “synchronize” call but we have found over huge numbers of real-life user runs it is probably more reliable if you do include it.

    PS Do NOT use Booleans in preferences. If you are a new programmer, it is iffy to understand the defaults and hence never maintainable. Stick to integers. (They are always an “integer zero” when first unused, so you have no problems.) Easy Peasy. Hope it helps.

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

Sidebar

Related Questions

I've got an iPhone app that loads a bunch of TableViews. The first time
On my main window I have a DataGridView that I wish to display my
This is my first time trying Pandas. I think I have a reasonable use
I have a new MVC 4 Application with a fairly basic View/Controller. The associated
I'm using constructor injection for the first time and wish to write my code
I'm a first time iPhone application developer and I'm developing application for my client
I'm looking at using ELMAH for the first time but have a requirement that
Desired Workflow First I wish to fetch a particular set of questions and answers
I wish to know how Old Linux scheduling algorithm SJF (shortest job first) calculates
Trying to use Database Designer in VS2010 for the first time. I started adding

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.