我想实现UISearchController,使用本教程一步一步:
使用MKLocalSearchRequest搜索地点并使用UISearchController显示结果
在本节中......
...我在步骤3中遇到问题.设置表视图数据源
extension LocationSearchTable {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return matchingItems.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell")!
let selectedItem = matchingItems[indexPath.row].placemark
cell.textLabel?.text = selectedItem.name
cell.detailTextLabel?.text = ""
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试override
从cellForRowAtindexPath
tableView函数中删除,在这种情况下我在Xcode中没有错误,但执行后出错:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView (<UITableView: 0x7ff8e03a3800; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H;
gestureRecognizers = <NSArray: …
Run Code Online (Sandbox Code Playgroud) 我是 Swift 新手,我有一个错误问题,这个类与 key 的键值编码不兼容。
我重新阅读了所有相关主题,但没有找到解决此问题的方法。
请检查代码并给我一些建议,我做错了什么?
class FriendScore: NSObject {
var name:String?
var highestScore:Int?
}
var allScoresArr = [FriendScore]()
var dataArr = [[String:Any]]()
dataArr =[["name": "Ben", "highestScore": 15],["name": "Alex", "highestScore": 12]]
for user in dataArray {
if let dictionary = user as? [String:Any] {
let friendScore = FriendScore()
//Error Happens Here "Thread Breakpoint"
friendScore.setValuesForKeys(dictionary)
allScoresArr.append(friendScore)
}
}
print(allScoresArr)
Run Code Online (Sandbox Code Playgroud)
错误:
<__lldb_expr_73.FriendScore 0x608000266080>
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key highestScore.
'libc++abi.dylib: terminating with uncaught …
Run Code Online (Sandbox Code Playgroud)