2011-02-27 32 views
2

所以我有一個UITableViewControler在縱向模式下顯示tableview。旋轉的模態視圖

只要我旋轉iPhone我想在橫向模式下呈現模態視圖。

在的tableView我使用:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

並處理本模態視圖:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { 
     if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)) 
     { 
      NSLog(@"Push page view"); 
      PagingViewController *s = [[PagingViewController alloc] initWithNibName:@"PagingView" bundle:nil]; 
      s.hidesBottomBarWhenPushed = YES; 

      [self presentModalViewController:s animated:YES]; 
      [s release]; 
     } 
} 

模態視圖我有以下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} 

並以忽略它自我的模態視圖,我這樣做:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { 
    if (interfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
     NSLog(@"Dismiss my self"); 
     [self.parentViewController dismissModalViewControllerAnimated:YES]; 
    } 
} 

一些這是如何工作兩次。 第三次我將iPhone從縱向模式旋轉到橫向模式時,出現訪問錯誤。

我不知道什麼給了我錯誤。 任何照顧一槍?

+0

訪問錯誤發生在哪一行? (您可以在調試器中看到這一點。) –

+0

每當我嘗試在第二個模式關閉之後在UITableViewController中執行某些操作時。所以我想UITableViewController也會被解僱。 – esbenr

+0

我有各種各樣的問題做類似的事情,回到3.0。看起來像一個已知的錯誤,加上種族條件。最後,使用設備通知來監視更改;看到這個例子:http://stackoverflow.com/questions/1500060/view-controller-not-getting-shouldautorotatetointerfaceorientation-messages-on – petert

回答

0

我能想到的最簡單的方法是實現-shouldAutorotate ...並關閉模態視圖並返回NO以中止旋轉。也許這足以避免任何併發問題。如果這個建議不符合你的要求,請看看NSNotificationCenter。