app starts from second viewcontroller instead of first in iPhone 4

Discussion in 'iOS Programming' started by newlearner, Oct 18, 2010.

  1. newlearner macrumors member

    newlearner

    Joined:
    Jul 30, 2009
    Location:
    india
    #1
    Hello

    I have an app with two views. Suppose viewcontroller A and viewcontroller B. In iPhone 3G, app launches with View A and then after a delay of 3 seconds, view B comes up.

    But in iPhone 4, app always launches with view B.

    I have set the UIApplicationExitsOnSuspend to YES for always starting from view A.

    But view A never shows up in iPhone 4.

    On simulator everything works fine.This behavior on the device has been noticed during testing via ad-hoc distribution. Hence I am unable to debug it.

    Here is the code:

    In the appDelegate implementation, am calling the first view as:
    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [[UIApplication sharedApplication] setStatusBarHidden:YES
                                            withAnimation:UIStatusBarStyleDefault];
    
    ViewControllerA *avc=[[ViewControllerA alloc]initWithNibName:@"ViewControllerA" bundle:nil];
    
    [window addSubview:avc.view];
    [window makeKeyAndVisible];
    return YES;
    }
    
    view did load of ViewControllerA:

    Code:
     - (void)viewDidLoad {
              [NSThread sleepForTimeInterval:3.5];
              viewControllerB *bvc=[[viewControllerB  alloc]initWithNibName:@"viewControllerB"                                                         bundle:nil];
    
    [self.view addSubview:bvc.view];
    [super viewDidLoad];
    }
    
    Using IB in viewControllerA.xib, I have put up an UIImageView.

    Whenever the app loads up in the device, instead of viewControllerA, always viewControllerB shows up.

    Thanks
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Where you do that NSThread sleep: don't ever do that. You are sleeping the main thread of the application making it totally unresponsive. You are lucky that iOS is not killing your app for taking to long to start up. Use an NSTimer instead.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    What is the purpose of viewcontroller A? Is it just a splash screen? Say it isn't so.
     
  4. newlearner thread starter macrumors member

    newlearner

    Joined:
    Jul 30, 2009
    Location:
    india
    #4
    @robbieduncan: thanks, your tip worked like a charm. NSThread was the one posing the issue.

    @dejo: the splash screen is different. viewControllerA contains an image which serves as an instruction to use the app.
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Relieved to hear it.
     

Share This Page