我的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
}
最佳答案
let stringInput = "Ramu"
let stringInputArr = stringInput.components(separatedBy: " ")
var stringNeed = ""
for string in stringInputArr {
stringNeed = stringNeed + String(string.characters.first!)
}
print(stringNeed)
关于ios - uitableview单元格cellForRowAtindexPath在swift3中从名称中提取第一个字母,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47448535/