Проблема с вашим кодом заключается в том, что вы возвращаете метод 1 + posts.count
из numberOfRowsInSection:
, как показано ниже.
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1 + posts.count
}
, и вы не обрабатываете, когда ваш путь индекса достигнут на posts.count
.
Решение
Таким образом, решение состоит в том, чтобы вернуть posts.count из numberOfRowsInSection: метод.
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
ИЛИ вы можете обработатьэта фатальная ошибка в методе cellForRow:
.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
.
.
.
//Handle fatal error here
cell.set(details: details[indexPath.row])
return cell
}
.
.
.
//Handle fatal error here
cell.set(post: posts[indexPath.row - 1])
return cell
}