2013-03-14 68 views
7

因此,在我的通用應用程序中,我有一個人可以從我們的系統中查看現有註釋列表的部分(通過簡單的Web服務檢索),然後創建一個新註釋if他們要。所以對於iphone來說,這是非常簡單的佈局,一個TableViewController用於在NavigationBar上顯示帶有添加新項目的模式視圖的「添加」按鈕的列表。但在iPad上,同樣的佈局有很多浪費的空間,所以我選擇使用popOver方法在popOver中顯示列表,然後讓它們從那裏添加。我的問題是,當用戶點擊PopOver視圖中的Add按鈕時,模式視圖將全屏顯示,而不是在彈出視圖中彈出。下面的代碼我到目前爲止:從彈出式視圖中提取Modal View Controller

-(void) AddButtonPressed:(id)sender { 

NewNoteVC *newNote = [[[NewNoteVC alloc] initWithNibName:@"NewNoteVC" bundle:nil] autorelease]; 
newNote.defaultClientID = defaultClientID; 
UINavigationController *navCon = [[[UINavigationController alloc] initWithRootViewController:newNote] autorelease]; 
if ([isPopOver isEqualToString:@"YES"]) { 
    [navCon setModalInPopover:YES]; 
    [self.navigationController setModalInPopover:YES]; 
    [self.navigationController presentModalViewController:navCon animated:YES]; 
} 
else { 
    [self.navigationController presentModalViewController:navCon animated:YES]; 
} 

}

的「isPopOver」字符串就是從以前的屏幕調用此TableView中(我知道我可以關掉這個爲布爾更好發送的佔位符性能我只是把它放在一起真正快速地嘗試它)。我知道我搞砸了,我只是不知道我需要什麼設置才能正常工作。

+0

[UIPopoverController模態提供的可能重複不能在iOS 5中工作](http://stackoverflow.com/questions/7806979/uipopovercontroller-presented-modally-doesnt-work-in-ios-5) – Till 2013-03-14 19:52:02

回答

22

您需要定義視圖控制器的modalPresentationStyle是「當前上下文」。

navCon.modalPresentationStyle = UIModalPresentationCurrentContext; 

這將導致在模態視圖控制器填充像酥料餅的根控制器酥料餅。

+2

這是我需要的設置,謝謝。 – 2013-03-14 21:03:12

2

嘗試使用的presentViewController:animated:completion:代替presentModalViewController:animated:並設置self.navigationController.definesPresentationContext = YES

相關問題