Я следую за потрясающим Стэнфордом cs193p курс о iTunes, и я теперь в лекции № 7 и домашняя работа № 3.
Я просто пытаюсь сделать работы SplitViewController правильно над iPad..., но похоже, что мои методы делегата UISplitViewControllerDelegate не называют, когда ориентация устройства изменяется.
Вот то, что я получил до сих пор:
- Я создал совершенно новую Раскадровку iPad, добавил SplitViewController с UIViewController как Владелец (CalculatorViewController) и другой UIViewController как Деталь (GraphViewController). Я думаю, что сделал все правильно.
- Мой GraphViewController.h осуществляет протокол UISplitViewControllerDelegate:
@interface GraphViewController : UIViewController
- Мой GraphViewController.m устанавливает делегата SplitViewController в себе:
- (void)awakeFromNib {
[super awakeFromNib];
self.splitViewController.delegate = self;
}
- Мой GraphViewController.m осуществляет необходимые методы:
// asks the delegate whether the first view controller should be hidden for the specified orientation
- (BOOL)splitViewController:(UISplitViewController *)svc
shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation
{
//only show the master controller in landscape mode
return UIInterfaceOrientationIsPortrait(orientation);
}
// tells the delegate that the specified view controller is about to be hidden (must add a popover button)
- (void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc
{
barButtonItem.title = aViewController.title;
//add the button to the toolbar
NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
[toolbarItems insertObject:barButtonItem atIndex:0];
self.toolbar.items = toolbarItems;
}
// tells the delegate that the specified view controller is about to be shown again (must remove popover button)
- (void) splitViewController:(UISplitViewController *)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
//hide the bar button item on the detail controller
NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
[toolbarItems removeObject:barButtonItem];
self.toolbar.items = toolbarItems;
}
- Мой GraphViewController.m поддерживает все ориентации:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;//support all types of orientation
}
Теперь, когда я запускаю приложение (Xcode 4.2 на снежном барсе, iOS 5.0, Симуляторе iPad 5.0), splitViewController:willHideViewController:withBarButtonItem:forPopoverController: метод называют, моя Основная точка зрения скрыта, и кнопка, как показывают с моей точки зрения Детали показывает Основное представление в PopOver (причина, я нахожусь в режиме портрета).
Однако, когда я изменяю ориентацию устройства (к альбомному режиму... все еще использование симулятора), ничего не происходит, ни один из вышеупомянутых методов не называют снова. Я заканчиваю с Основным представлением, все еще скрытым и кнопка PopOver, все еще показанная, когда на самом деле, я хотел бы, чтобы Основное представление было показано и кнопка PopOver, которая будет скрыта.
Что я делаю неправильно?
Действительно ли это - проблема с моим кодом, с XCode, с симулятором?