【发布时间】:2017-11-23 05:58:14
【问题描述】:
我的 UITableView 有一个自定义单元格,我将显示项目名称的第一个字符like this"below image"
所以我的问题是如何创建它如何从通过 json 获取的名称数据中提取第一个字母。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ProjectTabTableViewCell
cell.colorViewOutlet.layer.cornerRadius = 25.0
let projectLst = projectList[indexPath.row]
let str = projectLst.NameEN
print(str?.characters.first?.description ?? "");
projectNameFirst = [str?.characters.first?.description ?? ""]
print(projectNameFirst)
cell.wordsLabel?.text = projectNameFirst[indexPath.row]
cell.nameLabel?.text = projectLst.NameEN
cell.colorViewOutlet.backgroundColor = .random
return cell
}
【问题讨论】:
-
请说清楚。
-
你能分享你的 JSON 和代码吗..
-
第一个字母和名字有什么关系?在图像中似乎没有关系。
标签: ios json swift uitableview uilabel