presentModalViewController in viewDidLoad on first launch

I’ve been searching around but unfortunately have had no luck.

My app requires the user to sign in/sign up the first time he or she launches the app. I know how to determine first launch (using NSUserDefaults) but whenever I try to present the modal containing the sign in/ sign up controls, nothing happens.

  • Error: Mutating method sent to immutable object for NSMutableArray from JSON file
  • viewDidLoad is called only the first time
  • UIView - How to get notified when the view is loaded?
  • ViewController Appears to Transition Twice
  • Unable to set frame correctly before viewDidAppear
  • How do I detect an iPad's interfaceRotation at the start?
  • Here’s what I have:

    -(void)viewDidLoad {
        [self showLogin];
        [super viewDidLoad];
    }
    
    -(void)showLogin {    
        FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"AccountView" bundle:nil];
        controller.delegate = self;
    
        controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentModalViewController:controller animated:YES];
    
        [controller release];
    }
    

    However, nothing happens. The main view just loads as normal. Any help is greatly appreciated.

    -Giles

    4 Solutions Collect From Internet About “presentModalViewController in viewDidLoad on first launch”

    [UPDATE]

    Fixed simply by using..

    -(void)viewDidAppear:(BOOL)animated 
    {
    
    }
    

    instead of

    -(void)viewDidLoad
    {
    
    }
    

    Thanks anyway!

    /idiocy

    I had the same issue and ended up using viewDidAppear as well. The only problem with the viewDidAppear approach is that if you load other UIViewControllers on top, then reshow the base, then your setup code gets called over and over. I ended up having to add a boolean value (initialised to YES) to this view controller and check that value before deciding what to do. Hope this helps someone…

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:(BOOL)animated];
    
        if(justLaunched)
        {
            justLaunched = NO;
            if(settingsFileExists)
            {
                [self displayMainView];
            }
            else
            {
                [self displaySetupView];
            }
        }
    }
    

    How about using performSelector:withObject:afterDelay in the viewDidLoad function? That’s how I do it, with a short delay of 0.1s.

    And invoking this in the viewDidLoad isn’t very safe : the sequence viewDidLoad / viewDidUnload can occur at runtime when the iPhone needs to release some views in order to get back some free memory.

    The side effect of such sequence would be that your login controller would be shown…

    As you said the viewDidAppear looks better but not simply put it at the end of the appDidFinishedLaunching the delegate of your UIApplication?