我有两个数组,我的用户类有名称和用户图像
var users = Array<User>()
var filteredTableData = Array<User>()
override func viewDidLoad() {
super.viewDidLoad()
// Reload the table
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
for var i = 0 ; i < Dataholder.sharedInstance(self.view).users.count; ++i
{
users.append(Dataholder.sharedInstance(self.view).users[i])
}
}
然后
func updateSearchResultsForSearchController(searchController: UISearchController)
{
filteredTableData.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "Name CONTAINS[c] %@", searchController.searchBar.text)
println(searchPredicate)
let array = (users as NSArray).filteredArrayUsingPredicate(searchPredicate) as! [User]
filteredTableData = array
self.tableView.reloadData()
}
和ı得到错误
NSForwarding:警告:'Project.User'类的对象0x7fe08604e730没有实现methodSignatureForSelector: - 提前出现问题 无法识别的选择器 - [Project.User valueForKey:]
我想要返回我的用户对象,而不仅仅是名称在互联网上有很多例子,但只搜索任何文本,我想按名称搜索,但返回像用户对象一样的filteredTableData