2012-12-17 41 views
0

當我嘗試使用popToRootViewControllerAnimated方法我的屏幕變黑。 我想我真的回到了預期的視野,因爲如果我將設備旋轉到橫向視圖顯示正確。iOS使用navigationController popToRootViewControllerAnimated

這是我的申請的上下文中:

甲視圖控制器A被嵌套到導航控制器。點擊一個按鈕觸發一個segue給viewcontroller B.在viewcontroller B的viewDidLoad方法中,創建一個連接助手以便收集我們服務器數據庫上的一些數據。在創建時,助手正在檢查設備是否連接到互聯網。如果它不那麼「popToRootViewControllerAnimated」被稱爲返回視圖 - 控制A.

這裏是助手的代碼:

+(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"]; 
} 

一旦「popToRootViewControllerAnimated」方法被調用,我可以看到從控制器查看滑動和黑色屏幕顯示。

正如我前面提到的那樣,感覺就像我被帶回到viewcontroller A(將設備從縱向旋轉到橫向顯示視圖),但視圖看起來像是在屏幕的框架之外。

希望我明白了一切。

感謝

+0

感謝這個線程(http://stackoverflow.com/questions/5301014/ios-popviewcontroller-unexpected-behavior)我在尋找我認爲的解決方案的好路徑。如果我在viewdidappear中彈出根控制器,一切正常。我認爲這確實是一個動畫問題。 – Regis

回答

1

正如我提到了我的意見,啪在viewDidAppear方法根控制器似乎做的伎倆。

+0

不錯的解決方案。你可以接受你自己的答案(幾天後,我想),你應該這樣做。 – matt

相關問題