【发布时间】:2017-07-24 17:02:07
【问题描述】:
我正在使用库“RealmSearchViewController”并覆盖一个方法。但是调用视图控制器中的方法不是练习。而是执行库中的代码,打印出一条消息“您需要实现 searchViewController(controller:,cellForObject object:,atIndexPath indexPath:)”。我的代码如下所示(我去掉了一些无关的代码)
import UIKit
import RealmSwift
import RealmSearchViewController
class SearchController: RealmSearchViewController {
override func searchViewController(_ controller: RealmSearchViewController, cellForObject object: Object, atIndexPath indexPath: IndexPath) -> UITableViewCell {
let record = object as? WorkorderRecord
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! WorkorderCell
....
return cell
}
这是库中的原型:
open func searchViewController(_ controller: RealmSearchViewController, cellForObject object: Object, atIndexPath indexPath: IndexPath) -> UITableViewCell {
print("You need to implement searchViewController(controller:,cellForObject object:,atIndexPath indexPath:)")
return UITableViewCell()
}
【问题讨论】:
-
您是直接使用控制器还是库控制器?你能显示控制器类实现的代码吗
-
我的控制器是 RealmSearchViewController 的子类。我在编辑后的问题中添加了开始代码。
-
我能想到的唯一一件事就是仔细检查您实际上在故事板或笔尖中使用了
SearchController。 -
就是这样!!!我不小心在情节提要中选择了 RealmSearchViewController。非常感谢。如果您将您的建议作为我问题的答案,我将关闭该问题并给予您信任。