我在这里只找到了一个答案。我的问题是我没有使用Character
s 除了那是 aString
是 - 一个字符的集合。我试着把它变成一个String
可视化;
let name = String(array[indexPath.section][indexPath.row])
但我得到同样的错误无法将“字符”类型的值分配给“字符串?” .
这是我的手机:
struct SectionStrings {
let sections = ["Stuff", "More Stuff", "Best Stuff"]
}
struct ArrayStrings {
let array = ["Little Stuff", "Bigger Stuff", "Biggest Stuff"]
}
struct DetailArrayStrings {
let detailArray = ["Teeny Stuff", "Teentsie Weentsie Stuff", "Invisible Stuff"]
}
这是我的控制器:
let sections = SectionStrings().sections
var array = ArrayStrings().array
let detailArray = DetailArrayStrings().detailArray
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! SettingsCell
let name = array[indexPath.section][indexPath.row] // errors here
cell.textLabel?.text = name
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 17)
cell.textLabel?.textColor = .white
let detailName = detailArray[indexPath.section][indexPath.row] // and here
cell.detailTextLabel?.text = detailName
cell.detailTextLabel?.font = UIFont.systemFont(ofSize: 15)
cell.detailTextLabel?.textColor = .white
cell.detailTextLabel?.numberOfLines = 0
cell.selectionStyle = .none
cell.backgroundColor = .black
return cell
}