Как правильно отображать данные в ячейках таблицы - PullRequest
0 голосов
/ 23 января 2019

Только первый элемент из массива отображается в ячейках с интервалом.

У меня нет проблем с отображением данных в простых ячейках без пробелов, но когда мне нужно разделить ячейки и изменить свой код, отображается только первый элемент

let test = ["1","2","3"]
func numberOfSections(in tableView: UITableView) -> Int {
    return test.count
}

func tableView(_ tableView: UITableView, numberOfRowsInSection 
    section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    let cellSpacingHeight: CGFloat = 10
    return cellSpacingHeight
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerView = UIView()
    headerView.backgroundColor = UIColor.clear
    return headerView
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "SellerPlacesCell", for: indexPath) as! SellerPlacesCell
    cell.backgroundColor = UIColor.white.withAlphaComponent(0.5)
    cell.namePlace.text = test[indexPath.row]
    return cell
}

enter image description here Как это исправить?

если в

func tableView(_ tableView: UITableView, numberOfRowsInSection 
    section: Int) -> Int {
    return 1
}
return 1 

я заменяю return 1 на test.count это: enter image description here

1 Ответ

0 голосов
/ 23 января 2019

Замените

cell.namePlace.text = test[indexPath.row]

на

cell.namePlace.text = test[indexPath.section]

интервал предназначен для того, чтобы вы отображали секции, поэтому вам нужно получить доступ к массиву с section, а не row

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...