b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

ios web markup iOS 9学习系列:Search API(4)

电脑杂谈  发布时间:2017-06-08 09:05:39  来源:网络整理

在写这篇文章的当下,Xcode7(Beta3)的最新版本有一个问题那就是一个用于修复的user activity的 userInfo 属性会变成空。这就是为什么我会处理errors以及展示一个userInfo(作系统返回的)信息的警告。

再次编译运行你的APP,搜索一个节目。当你在搜索结果里轻触一个节目时,APP将会直接将你带到详细信息的view controller并展示出你选择的节目的当前信息。

03.png

2.使用Core Spotlight 框架

另外一些在iOS9中能使你的内容可被用户搜索得到的APIs就是Core Spotlight 框架。这个框架有一个类似的设计并且能够给你提供更多的关于你想被搜索到的内容的信息。

在你可以使用Core Spotlight框架之前,我们需要把这个工程同这个框架链接起来。在Project Navigator中,选中这个工程然后打开最上面的Build Phases栏目。接下来,展开 Link Binary With Libraries 区域然后点击加号按钮。在弹出的菜单中,搜索 CoreSpotlight 然后把你的工程跟这个框架链接起来。重复这些步奏来链接 MobileCoreServices 框架。

Screen Shot 2015-07-10 at 4.44.47 PM.png

接下来,为了确保我们的APP提供的搜索的结果确实来自于Core Spotlight,在你的测试机或者模拟器上删除你的应用然后在DetailViewController类中注释掉下面的这条语句:

activity.becomeCurrent()

最后,打开MasterViewController.swift然后在Show结构体定义之前添加下面的语句:

import CoreSpotlight 
import MobileCoreServices

接下来,在MasterViewController类的viewDidLoad方法里添加下面的代码:

var searchableItems: [CSSearchableItem] = []
for show in objects {
    let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
     
    attributeSet.title = show.name
     
    let dateFormatter = NSDateFormatter()
    dateFormatter.timeStyle = .ShortStyle
     
    attributeSet.contentDescription = show.genre + "\n" + dateFormatter.stringFromDate(show.time)
     
    var keywords = show.name.componentsSeparatedByString(" ")
    keywords.append(show.genre)
    attributeSet.keywords = keywords
     
    let item = CSSearchableItem(uniqueIdentifier: show.name, domainIdentifier: "tv-shows", attributeSet: attributeSet)
    searchableItems.append(item)
}
 
CSSearchableIndex.defaultSearchableIndex().indexSearchableItems(searchableItems) { (error) -> Void in
    if error != nil {
        print(error?.localizedDescription)
    }
    else {
        // Items were indexed successfully
    }
}


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-51781-4.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 黄庭佐
      黄庭佐

      美国佬既然自己送来了

    热点图片
    拼命载入中...