presentModalViewController in viewDidLoad on first launch

a 夏天 提交于 2019-12-01 03:16:44
Giles Van Gruisen

[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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!