ios - 弹出窗口中的 UIReferenceLibraryViewController

标签 ios objective-c ipad uiview uipopovercontroller

如果搜索一个词,我有这部分代码可以调出字典:

- (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/

相关文章:

ios - 仅在可见单元格上播放视频

ios - 处理 iPad Mini 屏幕尺寸

ios - 从 NSMutableArray 中获取数据

ios - 将 100MB XML 文件导入我的 iPad 应用程序

ios - iPhone 上的脉冲动画

ios - 如何通过编码重启IOS应用程序?

objective-c - 如何从 appdelegate.mm 调用 helloworldlayer.mm 中的方法

iphone - 重用 UILabel 样式的正确方法是什么?

asp.net - iPad 上的 Safari 有时无法识别 ASP.NET 回发链接

ruby-on-rails - 通过rails向Ipad提供mp4文件的正确方法是什么?