如果搜索一个词,我有这部分代码可以调出字典:
- (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 屏幕。我怎样才能让它只在 subview 中打开,只是屏幕的一部分?
最佳答案
使用 UIPopoverController
,就像在 native 应用程序中使用它一样。
self.popover = [[UIPopoverController alloc] initWithContentViewController:referenceLibraryVC];
[self.popover presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
您需要保留弹出框 Controller 直到它被关闭。设置委托(delegate),你可以在它被解散时监听,这样你就可以释放它。
关于ios - 弹出窗口中的 UIReferenceLibraryViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20643742/