我的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
}
答案 0 :(得分:0)
从代码
下面的字符串使用中获取第一个字符if(isset($_POST['submit']))
{
foreach($_POST['award_allocations'] as $award_code => $student_codes) {
printf("Award code: %s allocated to Student codes: %s\n",
$award_code,
implode(', ', $student_codes)
);
}
$lock = isset($_POST['lock']) ? true : false;
}
希望这会对你有所帮助
答案 1 :(得分:0)
let stringInput = "Ramu"
let stringInputArr = stringInput.components(separatedBy: " ")
var stringNeed = ""
for string in stringInputArr {
stringNeed = stringNeed + String(string.characters.first!)
}
print(stringNeed)