既然你有用於存儲有關當前正呈現的酥料餅控制器的其他信息的屬性popoverControllerRestorationDictionary
,這裏是你如何能恢復酥料餅控制器的想法:
- (void)presentPopoverController:(UIPopoverController *)popoverController fromRect:(CGRect)rect animated:(BOOL)animated
{
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];
self.popoverControllerRestorationDictionary = @{ @"popoverController" : popoverController, @"rect" : [NSValue valueWithCGRect:rect] };
}
- (void)dismissedPresentedPopoverController
{
self.popoverControllerRestorationDictionary = nil;
}
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
...
if (self.popoverControllerRestorationDictionary != nil) {
[coder encodeBool:YES forKey:@"restorePopoverController"];
UIPopoverController *popoverController = [self.popoverControllerRestorationDictionary objectForKey:@"popoverController"];
[coder encodeObject:popoverController.childViewController forKey:@"popoverController.childViewController"];
NSValue *rectValue = [self.popoverControllerRestorationDictionary objectForKey:@"rect"];
[coder encodeObject:rectValue forKey:@"popoverController.targetRect"];
}
}
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
...
if ([coder decodeObjectForKey:@"restorePopoverController"]) {
UIViewController *childViewController = [coder decodeObjectForKey:@"popoverController.childViewController"];
CGRect targetRect = [[coder decodeObjectForKey:@"popoverController.targetRect"] CGRectValue];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithChildViewController:childViewController];
[self presentPopoverController:popoverController fromRect:targetRect animated:NO];
}
}
該解決方案是不太理想,所以如果有人想出更好的東西,請告訴我!