【发布时间】:2017-02-10 19:53:30
【问题描述】:
我想在UITablViewCell 中突出显示Strings,但这段代码并不能帮助我创建那种效果。 allData 是 CoreData,我循环遍历它以检索每个元素,如果 cell.textLabel.text 有这些元素,我希望 allData 中的所有元素都以颜色突出显示,在本例中为黄色。我在这里做错了什么?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let allData = Singlton.Singleton.getAllData()
cell.textLabel?.text = someData[indexPath.row]
cell.detailTextLabel?.text = ""
for i in allData {
if someData[indexPath.row].contains(i.string!.lowercased()) {
cell.textLabel?.textColor = UIColor.yellow
} else {
cell.textLabel?.textColor = UIColor.white
}
}
return cell
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return someData.count
}
【问题讨论】:
-
您知道比较不起作用还是没有着色?执行是在 if 还是 else 语句中?
-
我的 allData 数组中有很多字符串,但其中一个只是突出显示
-
你想使用第三部分库吗?
-
是的,我可以使用 Cocoapods!
标签: swift uitableview for-loop