UIReferenceLibraryViewController的使用(调用系统词典)

来源:互联网 发布:知乎女神王珏 编辑:程序博客网 时间:2024/05/18 00:39

在程序中使用苹果的词典来查询词汇,即一些软件的“词典"功能

UIReferenceLibraryViewController和MFMessageComposeViewController很相似,提供了最小化配置的系统层viewController,可以直接被present显示。


可用需要查找term来进行初始化:

    UIReferenceLibraryViewController *referenceLibraryViewController =
    [[UIReferenceLibraryViewController alloc] initWithTerm:@"apple"];
    [viewController presentViewController:referenceLibraryViewController  animated:YES  completion:nil];
       


这种行为和用户点击UITextView中高亮词汇弹出的"定义"的UIMenuItem的效果差不多。

UIReferenceLibraryViewController也提供了一个类方法dictionaryHasDefinitionForTerm:,开发者可以在dictionary view controller出现之前调用这个方法,就可以在不必需的时候不显示那个viewController了。

[UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:@"apple"];

在这两种情况下,UIReferenceLibraryViewController会以非常好的形式去格式化搜索结果,所以并不需要开发者手动去掉空格或者调整大小写来优化搜索。



0 0
原创粉丝点击