0

When I try to use popToRootViewControllerAnimated method my screen turns black. I think I really get back to the expected view though because if I rotate my device to landscape the view appears correctly.

Here is the context of my application:

A viewcontroller A is nested into a navigation controller. Clicking on a button triggers a segue to viewcontroller B. In the viewDidLoad method of viewcontroller B a connection helper is created in order to collect some data on our server database. While being created the helper is checking if the device is connected to internet. If it's not then "popToRootViewControllerAnimated" is called to return to viewcontroller A.

Here is the code of the helper:

 +(AFHTTPClient*) getClient {
    if (!client) {
        [self createClient];
    }

    if (client.networkReachabilityStatus <AFNetworkReachabilityStatusReachableViaWWAN) {

        [currentController.navigationController popToRootViewControllerAnimated:YES];
        //[[[UIAlertView alloc] initWithTitle:@"Connection Problem" message:@"You don't seem to be connected to internet. Please enable WI-Fi or 3G then try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil] show];
           client = nil;
    }
    return client;
}

+(void) createClient{
    NSURL* baseUrl = [NSURL URLWithString:[[@"http://" stringByAppendingString:[ApplicationTask GetApiUrl]] stringByAppendingString:@"/"]];
    client = [AFHTTPClient clientWithBaseURL:baseUrl];
    client.parameterEncoding = AFJSONParameterEncoding;
    [client registerHTTPOperationClass:[AFJSONRequestOperation class]];
    [client setDefaultHeader:@"Accept" value:@"application/json"];
    [client setDefaultHeader:@"Content-Type" value:@"application/json"];
}

Once the "popToRootViewControllerAnimated" method as been called, I can see the view from controller A sliding and a black screen is showing up.

As I mentioned earlier it feels like I am brought back to viewcontroller A (rotating the device from portrait to landscape orientation show the view) but the view seems like outside the frame of the screen.

Hope I made everything clear.

Thanks

HDdeveloper
  • 4,396
  • 6
  • 40
  • 65
Regis
  • 375
  • 4
  • 16
  • Thanks to this thread (http://stackoverflow.com/questions/5301014/ios-popviewcontroller-unexpected-behavior) I am on the good path to find a solution I think. If I pop the root controller in the viewdidappear everything works fine. I think it's really a problem of animation. – Regis Dec 18 '12 at 16:02

1 Answers1

1

As I mentioned into my comment, popping to the root controller in the viewDidAppear method seem to do the trick.

Regis
  • 375
  • 4
  • 16
  • Nice solution. You are allowed to accept your own answer (after a couple of days have gone by, I think) and you should probably do so. – matt Dec 18 '12 at 17:06