Bối cảnh & Mục tiêu: Tôi có một ứng dụng iPad dựa trên UISplitViewController - cho đến bây giờ nó hỗ trợ 4 định hướng nhưng bây giờ tôi muốn khóa nó xuống chỉ phong cảnh. Tôi đã thay đổi shouldAutorotateToInterfaceOrientation
của bộ điều khiển chế độ xem trái để chỉ hỗ trợ chế độ nằm ngang, nhưng điều này sẽ dừng việc viewWillAppear
khỏi bị gọi.ViewWillAppear không nhận được gọi với UISplitViewController
Chi tiết: My xem điều khiển iPad được tổ chức như sau:
window
`-- splitVC (UISplitViewController)
`-- rootNav (UINavigationController)
`-- hvc (HostManagerViewController, derived from UIViewController)
`-- detailViewController (DetailViewController, derived from UIViewController)
này được thực hiện trong App delegate như dưới đây:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
HostManagerViewController *hvc = [[[HostManagerViewController alloc]
initWithNibName:nil bundle:nil] autorelease];
self.detailViewController = [[[DetailViewController alloc]
initWithNibName:nil bundle:nil] autorelease];
UINavigationController *rootNav = [[[UINavigationController alloc]
initWithRootViewController:hvc] autorelease];
UISplitViewController *splitVC= [[[UISplitViewController alloc] init] autorelease];
[splitVC setViewControllers:[NSArray arrayWithObjects:rootNav,
detailViewController, nil]];
splitVC.delegate = detailViewController;
[window addSubview:splitVC.view];
[window setRootViewController:splitVC];
return YES;
}
viewWillAppear
được gọi khi cả hai DetailViewController.m
và HostManagerViewController.m
chứa
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Console output:
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Hostmanager: Viewdidload
Should rotate called to hostmanager with 1
Hostmanager: viewwillappear
Nhưng khi tôi thay đổi mã của HostManagerViewController
thành
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (UIInterfaceOrientationIsLandscape(interfaceOrientation));
}
thì 'viewWillAppear` của HostManagerViewController không được gọi. Bảng điều khiển đầu ra
Should rotate called to hostmanager with 1 (1 is the numeric value of interfaceOrientation)
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 1
Should rotate called to hostmanager with 3
Hostmanager: Viewdidload
Should rotate called to hostmanager with 1
Chỉ chế độ Landscape được hỗ trợ trong Info.plist
EDIT: thông điệp chèn NSLog để theo dõi shouldAutorotateToInterfaceOrientation
, viewWillAppear
và ViewDidLoad
bạn có thể tải lên mẫu của dự án này không? – ACBurk
bạn đang chạy phiên bản iOS nào? – ACBurk
Tôi đang sử dụng 4.3. Giảm nó vào một testcase nhỏ hơn có thể được thực hiện. Tôi tải nó lên ở đâu? –