Я получаю сообщение об ошибке «Неустранимая ошибка: индекс выходит за пределы диапазона», когда я настраиваю две ячейки в табличном представлении, ShareSomthingCell исправляется и показывает только один раз, но пост-ячейка повторяется согласно базе данных
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1 + posts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
if let cell = tableView.dequeueReusableCell(withIdentifier: "ShareSomethingCell") as? DetailsCellInHomeScreen {
if currentUserImageUrl != nil {
cell.configCell(userImgUrl: currentUserImageUrl)
cell.shareBtn.addTarget(self, action: #selector(toCreatePost), for: .touchUpInside)
}
return cell
}
}
guard let cell = tableView.dequeueReusableCell(withIdentifier: "postCell", for: indexPath) as? PostTableViewCell else { return UITableViewCell() }
cell.btnComment.tag = indexPath.row
cell.btnComment.addTarget(self, action: #selector(toComments(_:)), for: .touchUpInside)
cell.favoritebutton.tag = indexPath.row
cell.favoritebutton.addTarget(self, action: #selector(favupdate(_:)), for: .touchUpInside)
cell.set(post: posts[indexPath.row - 1])
return cell
}
Я получаю сообщение об ошибке в этой строке
cell.set(post: posts[indexPath.row - 1])