'subscript (_ :)' недоступен: не может подписывать String с помощью Int (Swift 5) - PullRequest
1 голос
/ 01 октября 2019

Я нашел только один ответ на это здесь. Моя проблема в том, что я не использую Character s, за исключением того, что это String - набор символов. Я попытался сделать это String, а именно;

        let name = String(array[indexPath.section][indexPath.row])

но я получаю ту же ошибку Невозможно присвоить значение типа 'Character' для типа 'String?' .

Вот моя ячейка:

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
    }

1 Ответ

0 голосов
/ 01 октября 2019

Вы должны получить необходимые name для indexPath, используя row только как показано ниже,

let name = array[indexPath.row]
cell.textLabel?.text = name
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 17)
cell.textLabel?.textColor = .white

let detailName = detailArray[indexPath.row]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...