简体   繁体   中英

viewdidLoad/ viewDidAppear issue

I m loading a view which gets data from webservices. So depending upon the response code from server I show the current view or redirect to another view (ErrorView) if responsecode is 400.But I'm not being redirected to ErrorView and find a message in console "Attempt to present <ErrorView: 0xe332f30> on ViewController while a presentation is in progress!"

After googling it out I found to place vieDidLoad code to viewDidAppear After placing the entire code , it redirects to error view and works correctly.But in ios7 for Status bar issue I used the code

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
  if(responsecode==200)
   {
       //load current view
   }
  else
   {
     //Load anotherview(ErrorView)
   }
   float systemVersion=[[[UIDevice currentDevice] systemVersion] floatValue];
    if(systemVersion>=7.0f)
    {
        CGRect tempRect;
        for(UIView *sub in [[self view] subviews])
        {
            tempRect = [sub frame];
            tempRect.origin.y += 20.0f; 
            [sub setFrame:tempRect];
        }
    }

}

First the statusbar appear on the top ,then after loading the entire viewdata , view gets adjusted and status bar dropsdown by 20px , which looks odd.Can I get it to be adjusted automatically before the viewloads completely ?

Any ideas/suggestions would be appreciable.

I think, you should seperate this code

-(void)viewDidLoad
{
    float systemVersion=[[[UIDevice currentDevice] systemVersion] floatValue];

    if(systemVersion>=7.0f)
    {
        CGRect tempRect;
        for(UIView *sub in [[self view] subviews])
        {
            tempRect = [sub frame];
            tempRect.origin.y += 20.0f; 
            [sub setFrame:tempRect];
        }
    }
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
  if(responsecode==200)
   {
       //load current view
   }
  else
   {
     //Load anotherview(ErrorView)
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM