【问题标题】:UIReferenceLibraryViewController in a popover弹出窗口中的 UIReferenceLibraryViewController
【发布时间】:2014-01-05 18:44:52
【问题描述】:

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

- (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 屏幕。我怎样才能让它只在子视图中打开,只是屏幕的一部分?

【问题讨论】:

    标签: ios objective-c ipad uiview uipopovercontroller


    【解决方案1】:

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

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

    您需要保留弹出框控制器,直到它被解除。设置委托,当它被解除时您可以收听,以便您可以释放它。

    【讨论】:

    • 感谢您的意见,今天会尝试看看效果如何
    猜你喜欢
    • 2017-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-06
    • 2011-09-30
    • 2021-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多