弹出窗口中的UIReferenceLibraryViewController

如果搜索到一个单词,我会使用这部分代码来提取字典:

- (IBAction)searchButtonPressed:(id)sender { NSString *searchTerm = self.searchTextField.text; if([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:searchTerm]) { UIReferenceLibraryViewController *referenceLibraryVC = [[UIReferenceLibraryViewController alloc] initWithTerm:searchTerm]; [self presentModalViewController:referenceLibraryVC animated:NO]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Word not found" message:@"no definition" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; } } 

然而,它似乎只适用于xib中的主视图,并涵盖了更为诱人的iPad屏幕。 我怎样才能获得它,只在子视图中打开,只是屏幕的一部分?

使用UIPopoverController ,就像它在本机应用程序中使用一样。

 self.popover = [[UIPopoverController alloc] initWithContentViewController:referenceLibraryVC]; [self.popover presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

您将需要保留弹出控制器,直到它被解除。 设置委托,你可以在它被解雇时听,这样你就可以释放它。