【发布时间】:2015-12-31 17:10:17
【问题描述】:
我有一个由领域对象填充的表格视图,当我单击一个单元格时,它会将我带到另一个视图,该视图向我显示有关该对象的更多信息。我想为这个表视图添加一个搜索栏来检查对象的“fullName”属性。我知道如何为字符串数组添加搜索栏,但我还没有找到任何关于如何使用 Swift 2.0 的教程或指导。有什么帮助吗?
编辑:这就是我填充表格视图的方式
var dataSource : Results<Patient>!
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let identifier: String = "myCell"
var cell = tableView.dequeueReusableCellWithIdentifier(identifier)
if cell == nil {
cell = UITableViewCell(style: .Subtitle, reuseIdentifier: identifier)
}
let currentPatientInfo = dataSource[indexPath.section]
cell?.textLabel?.text = currentPatientInfo
cell?.accessoryType = UITableViewCellAccessoryType.DetailDisclosureButton
return cell!
}
我有部分数据,而不是行
编辑:我将RealmSwiftSearchController 添加到我的项目中,但有时在单击单元格时会出现此错误:
致命错误:在展开可选值时意外发现 nil
它指向这段代码:
extension RealmSearchViewController {
public override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
// The line below
let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as! Object
// Line ends
self.resultsDelegate.searchViewController(self, willSelectObject: object, atIndexPath: indexPath)
return indexPath
}
【问题讨论】:
标签: ios swift uitableview uisearchbar realm