swift - 搜索 UITableView 详细信息TextLabel 和 textLabel

标签 swift uitableview xcode7 textlabel detailtextlabel

我正在使用此 Stackoverflow URL How do I link the search bar to display results in swift/xcode 中显示的相同代码

我想知道是否还有一种方法可以搜索detailTextLabel,因为我在单元格中包含了副标题。执行过滤搜索时,字幕也不会与文本标签保持对齐。我正在 Xcode 7.1 和 Swift 2.0 中工作

最佳答案

是的,您可以这样做。在filterContentForSearchText函数下,只需使用“||”返回标题或副标题是否包含搜索字符串的 bool 值运算符。

例如,

func filterContentForSearchText(searchText: String, scope: String = "All") {
    filteredObjects = objects.filter { object in

  return object.title.lowercaseString.containsString(searchText.lowercaseString) || object.subtitle.lowercaseString.containsString(searchText.lowercaseString)

    }

    tableView.reloadData()
}

关于swift - 搜索 UITableView 详细信息TextLabel 和 textLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33894300/

相关文章:

swift - 递归函数替换json对象

swift - 即使设置了合并策略,保存时也会发生 NSConstraintConflicts

ios - Swift:ImageView 方面填充错误

ios - 动画期间 subview 堆叠

ios - 对不同 iphone 上的 ios 图像大小感到困惑

ios - iOS 的 Twitter UITableViewCell 链接检测(Swift)

ios - 如何在选择行时通过更改 UIView 来制作 messageRead 指示器?

c++ - ld : library not found for -lnfshared in iOS 9. 0

ios - 无法加载资源,因为 App Transport Security 策略要求使用安全连接

ios - 在 iOS 9 中滚动 UITableView 会导致标签重叠