0

時,這是一個棘手。我有一個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 

任何想法?

+0

嗯...情節變厚...如果我註釋掉'viewControllerToPresent.modalPresentationStyle = UIModalPresentationCurrentContext ;'然後塊被執行,但模式是全屏顯示的,而不是彈出框內。仍然令人討厭 –

回答

0

UIModalPrsentationCurrentContext風格是唯一可用的,如果編譯對iOS 3.2或更高。無法想象這是問題。

UIModalPrsentationCurrentContext的文檔也說:

當呈現在酥料餅的視圖控制器,此演示文稿的風格,才支持的過渡風格UIModalTransitionStyleCoverVertical。嘗試使用不同的轉換樣式會觸發異常。但是,如果父視圖控制器不在彈出窗口中,則可以使用其他轉換樣式(除了部分捲曲轉換)。

這是一個奇怪的一個。

你在iPhone和iPad上運行不同版本的iOS的任何機會呢?

+0

沒有...在iOS 6 SDK中構建並在兩臺設備上嘗試iOS 6。但請閱讀我對這個問題的評論,如果你評論出modalPresentationStyle,它會按預期工作(但是需要整個屏幕,而不僅僅是想要的popover) –

1

這似乎是一個巨大的錯誤。請報告給蘋果公司(我即將這樣做)。我在這裏找到了自己的方式,因爲我自己也發現了同樣的錯誤,並進行了谷歌搜索以查看是否有其他人在談論它。

我創建了一個非常小的示範項目,其結構是這樣的:

  • 的ViewController - 主視圖控制器

    視圖包含一個按鈕點擊我。

  • PopoverViewController - 在酥料餅呈現

    當絲錐我在主視圖控制器,它創建與一個UIPopoverController此 VC,PopoverViewController,作爲其內容視圖控制器;它的視圖也包含一個按鈕Tap Me。

  • PopoverViewController2 - 提出了「模態」,在同一酥料餅

    PopoverViewController2有modalPresentationStyle設置爲UIModalPresentationCurrentContext,因此可以在裏面酥料餅的出現。當您點擊彈出窗口中的Tap Me時,PopoverViewController會調用presentViewController:...

下面的代碼:

- (IBAction)doTapMe:(id)sender { 
    NSLog(@"about to present view controller"); 
    [self presentViewController:[PopoverViewController2 new] animated:YES completion:^{ 
     NSLog(@"in completion handler"); // never called! 
    }]; 
    NSLog(@"did present view controller"); 
} 

日誌上寫着「即將呈現視圖控制器」和「確實存在視圖控制器」,但「在完成處理程序」永遠不會出現,即使「模式「視圖控制器的視圖出現在彈出窗口中就好了。

(此外,更改爲animated:NO不僅不能解決問題,它會導致視覺干擾。)

相關問題