2012-08-06 69 views
0

我試圖做一個導航控制器,當旋轉爲橫向推新視圖壓入堆棧或旋轉回縱向時彈出了這一觀點。到目前爲止,我可以顯示橫向視圖,但只有當我可以通過再次將視圖控制器推入堆棧時才能獲取縱向圖像時。如果用戶不斷來回旋轉,我認爲堆棧將會耗盡內存。當我嘗試使用popToViewController時,沒有任何反應。有人可以幫助我獲得彈出功能嗎?不斷推視圖控制器

此方法在我的ViewController類:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
     toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     AppDelegate *delegate = 
     (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

     Landscape *landScape= 
     [[Landscape alloc] initWithNibName:@"Landscape" bundle:nil]; 

     [delegate.navController pushViewController:landScape animated:YES]; 
    } 
} 

此方法在我的園林類:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || 
      toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     AppDelegate *delegate = 
     (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

     ViewController *viewController= 
     [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 

     [delegate.navController pushViewController:viewController animated:YES]; 
    } 
} 

回答

1

看來你的ViewController應該已經是在棧上,所以你應該可以通過調用[delegate.navController popViewControllerAnimated:YES];,而不是[delegate.navController pushViewController:viewController animated:YES];

+0

好把它找回來。很酷的工作。我放置了[delegate.navController popViewControllerAnimated:YES];在景觀方法,它的工作。謝謝。 – apples 2012-08-07 02:57:14