時,這是一個棘手。我有一個UINavigationController的子類,它覆蓋了pop/push和present/dismiss方法。在這裏,我定製瞭如果UINavigationController子類包含在彈出窗口中時設置正確大小的行爲。沒有太想象,但我這樣做,不要寫我所有的ViewControllers的子類,並使用Autolayout。的UINavigationController不執行completionBlocks呈現的ViewController
然而,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
任何想法?
嗯...情節變厚...如果我註釋掉'viewControllerToPresent.modalPresentationStyle = UIModalPresentationCurrentContext ;'然後塊被執行,但模式是全屏顯示的,而不是彈出框內。仍然令人討厭 –