这个很棘手。我有一个 UINavigationController 的子类,它覆盖了 pop/push 和 present/dismiss 方法。如果 UINavigationController 子类包含在弹出框中,我在这里自定义行为以设置正确的大小。没什么太花哨的,但我这样做是为了不编写所有 ViewController 的子类并使用 Autolayout。
但是,and 的完成块presentViewController:animated:completion:
并dismissViewControllerAnimated:completion:
没有被执行。这是奇怪的部分:在 iPhone 上完全相同的代码可以正常工作,但在 iPad 上没有执行这些块。这是一个代码示例。
@interface SBNavigationController : UINavigationController
@end
@implementation SBNavigationController
- (void) presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
if ([viewControllerToPresent isKindOfClass:[UINavigationController class]])
{
UINavigationController *nav = (UINavigationController *) viewControllerToPresent;
[nav.topViewController setContentSizeForViewInPopover:kFullSizePopover];
} else
{
[viewControllerToPresent setContentSizeForViewInPopover:kFullSizePopover];
}
viewControllerToPresent.modalPresentationStyle = UIModalPresentationCurrentContext;
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
}
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion ;
{
[super dismissViewControllerAnimated:flag completion:completion];
}
@end
使用它的代码是这样的:
@implementation SBInviteFBContactViewController
...
- (void) createInviteByMailViewController
{
SBInviteMailViewController *mailInvite = [[SBInviteMailViewController alloc] initWithDelegate:self userInfo:_userInfo];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mailInvite];
[self.navigationController presentViewController:navController
animated:YES
completion:^{
NSLog(@"presentViewController:");
}];
}
#pragma mark SBInviteMailProtocol
- (void) invitedMailContacts:(NSArray *)contacts;
{
[self.navigationController dismissViewControllerAnimated:YES
completion:^{
NSLog(@"animation Ended");
if (contacts) {
[self.delegate invitedMailContact:contacts];
[self popViewControllerAnimated:YES];
}
}];
}
...
@end
有任何想法吗?