Some warning when trying to load other view controller

Discussion in 'iOS Programming' started by DennisBlah, Jun 1, 2014.

  1. DennisBlah, Jun 1, 2014
    Last edited: Jun 1, 2014

    DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    Hi all,

    I'm working on an app that will load some file from the web and parse it into the app.

    I have a problem, since I'm using Reachability class to know if the device is having a internet connection and if the host is reachable.

    If one of these 2 are false, then I'm presenting an different view controller, with an anouncement that, the user has no internet, or that the server is down.

    This is my code:
    Code:
    -(void)viewDidAppear:(BOOL)animated {
        [indicator startAnimating];
        CompanyappDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        
        internetReachable = [Reachability reachabilityForInternetConnection];
        [internetReachable startNotifier];
        hostReachable = [Reachability reachabilityWithHostName:@"www.mydomain.com"];
        [hostReachable startNotifier];
        
        loadData = [NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(loadData) userInfo:nil repeats:NO];
    }
    
    
    
    -(void)loadData {
        if(internetActive && hostActive) {
            //Ok, we have connection and the host is alive.
            //Doing all my loading data in here.
        } else {
            BOOL deviceIsIpad = NO;
            if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
                deviceIsIpad = YES;
            }
            UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPad" bundle:nil];
            if(!deviceIsIpad) {
                mainStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
            }
            UIViewController *nextView = [mainStoryboard instantiateViewControllerWithIdentifier:@"errorView"];
            [self presentViewController: nextView animated:YES completion:nil];
        }
    }
    
    It does work fine, however sometimes it does not work. The screen stays black. When I double tap the home button it does show me the 'errorView' but in app the screen stays black. In xCode i'm having this warning:

    Code:
    Warning: Attempt to present <dataView: 0x95ab070> on <connectionLoss: 0x97801a0> whose view is not in the window hierarchy!
    
     
  2. fabriciom macrumors 6502

    fabriciom

    Joined:
    Feb 17, 2008
    Location:
    Madrid, España
    #2
  3. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    Hi fabriciom,

    thanks, but Im actually using this to create an dictionary of the xml files Im using from my webhost.

    The problem is about loading the viewcontroller

    As you see in my code above, I'm using reachability class to check if the device has an internet connection, and if the host is reachable.
    If not, then load the connectionLoss view.

    But the strange thing is, in connectionLoss I'm doing exactly same thing, however when both booleans are true it loads back to the main viewcontroller. However I get the warning at that moment and won't go further
     
  4. fabriciom macrumors 6502

    fabriciom

    Joined:
    Feb 17, 2008
    Location:
    Madrid, España
    #4
    Hello Dennis,

    I suggest to use NSURLSession because its what is recommend by Apple (IOS 7). In another words instead of trying to see if you are connected or not just do your task and catch the error with the NSURLSession events. I think the reachability class is quite old.

    Just my 2 cents...
     
  5. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #5
    I understand what you mean. And you are right, ofcourse. But it's not the problem I'm strugling with.

    Still thanks for your tip about the connection check.:cool:
     

Share This Page