2011-06-09 63 views
0

什麼是處理UITabBarController時旋轉內部視圖的最新解決方案?我正在玩一個標準的應用程序視圖層次結構:在我的主應用程序委託文件中,我創建UITabBarController,然後創建UINavigationController,並用UITableViewController(帶有實例化的自定義子類)填充它,然後將該UINavigationController添加到第一個標籤欄項目。現在,我需要UITableViewController來自動旋轉。我知道,我需要實現shouldAutorotateToInterfaceOrientation在所有視圖控制器,因此,我實現了它在我的自定義的UITableViewController子類實現文件:iOS:請求獲取UITabBarController旋轉的最新解決方案

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return YES; 
} 

不過的UITableViewController沒有旋轉:(。現在,據我所知,有UINavigationController的和UITabBarController對象,這些對象位於我的TVC上方,但這兩個實例不是直接通過子類實例化的,所以沒有地方可以返回yes以進行自動旋轉。但是,我可以通過繼承UITabBarController並實現shouldAutorotateToInterfaceOrientation來解決此問題方法在其實現文件中,但我已經讀過,這是一個非推薦的方法,我的良心感覺不好:)另一個工作解決方案是實現一個類別對於UITabBarController(http://stackoverflow.com/questions/1269704/uitabbarcontroller-morenavigationcontroller-and-the-holy-grail-of-device-rotatio)...

所以,這兩個解決方案是唯一的我可以申請。有沒有其他「開箱即用」的解決方案,例如,在UITabBarController或smth上設置一些屬性?

回答

0

在UITableViewController子類或在UIViewController中實現UITableView的類中,需要爲tableView設置autoresizingMask。這多少有點像

self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

和TableView中應是確定和旋轉正常。

希望這個幫助:)