UIReferenceLibraryViewController in a popover

孤街醉人 提交于 2019-12-08 07:31:00

问题


I have this portion of code to pull up the dictionary if a word is searched:

- (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];
    }
}

however, it only seems to work on the main view in the xib and covers the entier iPad screen. How can I get it so that it only opens up in a subview, just a portion of the screen?


回答1:


Use a UIPopoverController, like it is used in native applications.

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

You will need to retain the popover controller until it is dismissed. Set the delegate and you can listen when it is dismissed so you can release it.



来源:https://stackoverflow.com/questions/20643742/uireferencelibraryviewcontroller-in-a-popover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!