gpt4 book ai didi

ios - uitableview cell cellForRowAtindexPath 从 swift3 中的名称中获取第一个字母

转载 作者:行者123 更新时间:2023-11-30 11:59:23 24 4
gpt4 key购买 nike

我的 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 cell cellForRowAtindexPath 从 swift3 中的名称中获取第一个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47448535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com