【发布时间】:2012-12-29 21:22:36
【问题描述】:
这个很棘手。我有一个 UINavigationController 的子类,它覆盖了 pop/push 和 present/dismiss 方法。如果 UINavigationController 子类包含在弹出框中,我在这里自定义行为以设置正确的大小。没什么太花哨的,但我这样做是为了不编写所有 ViewController 的子类并使用 Autolayout。
但是,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
有什么想法吗?
【问题讨论】:
-
mmm...情节变厚了...如果我注释掉
viewControllerToPresent.modalPresentationStyle = UIModalPresentationCurrentContext;行,则执行块,但模态显示全屏而不是在弹出框内。还是很烦
标签: ios uinavigationcontroller uikit presentmodalviewcontroller