我使用此代碼來呈現嵌入了navcontroller的彈出窗口。據我所知,它在iOS 5-8上的工作原理完全相同。該代碼是從NavBar中的按鈕調用的,所以我不必擔心在錯誤的時間設置它。我在#defines中設置了POPOVER_WIDTH和POPOVER_HEIGHT,因爲我有幾個popovers,我希望它們全都相同。
if (self.myPopoverController == nil) {
SettingsTableViewController *svc = [[SettingsTableViewController alloc]
initInManagedObjectContext:self.mObjContext
withScoreKeeper:self.scoreKeeper
withWordList:self.wordList];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:svc];
navController.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
popover.delegate = self;
popover.popoverContentSize = CGSizeMake(POPOVER_WIDTH, POPOVER_HEIGHT);
self.myPopoverController = popover;
[svc setPopover:popover];
// }
}
[self.myPopoverController presentPopoverFromBarButtonItem:buttonPressed permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];