Как добавить ячейку (пользовательскую) в tableView?Я пробовал следующее:
@IBAction func AddCommentButton(_ sender: Any) {
addComment() {
//1)
self.tableView.beginUpdates()
tableView.reloadRows(at: [arrayOfComments.count].indices, with: .automatic)
self.tableView.endUpdates()
//2)
// let cell = tableView.dequeueReusableCell(withIdentifier: "commentCell", for: tableView.numberOfRows(inSection: 0)) as! commentTableViewCell
// addTemporaryComment(cell: cell)
}
}
1) выходов:
Невозможно преобразовать значение типа 'Range.Index>' (он же 'Range') в ожидаемый тип аргумента '[IndexPath] '
2) Использование этого метода также приводит к множеству ошибок: все;
Использование неразрешенного идентификатора' indexPath ';Вы имели в виду «IndexPath»?
func addTemporaryComment(cell: commentTableViewCell) {
do {
let url = URL(string: (arrayOfComments[indexPath.row].user.profileImageUrlString)!)
let imageData = try Data(contentsOf: url!)
let image = UIImage(data: imageData)
cell.dateOfComment.text = arrayOfComments[indexPath.row].date
cell.commentText.text = arrayOfComments[indexPath.row].commentText
cell.profImage.image = image
cell.username.text = arrayOfComments[indexPath.row].user.username
} catch {
print(error, ": Failed in do block converting image")
}
}
}
Я даже не знаю, сработает ли это.
Как я могу это исправить, если это правильный способ сделать это, а если нет, как мне заставить это работать?