Мой tableView при запуске имеет раздел n.В каждом разделе есть только одна строка, но в каждой строке есть кнопка, которая добавляет строки раздела из массива.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let postModel = self.postsArray[section];
if (self.currentSection == section)
{
return 1 + (postModel.comments?.count)!;
}
else
{
print("nie rozszerzone")
return 1;
}
}
func numberOfSections(in tableView: UITableView) -> Int
{
return self.postsArray.count;
}
Я пытался сделать это следующим образом
func showComments(model: MGPostModel, sender: MGCommunityPostTableViewCell)
{
guard let path = self.communityTableView.indexPath(for: sender) else {
return;
}
print(path)
print(model.comments?.count as Any)
self.currentSection = path.section;
//model.comments.count is equal 3
let indexPath = IndexPath(row: (model.comments?.count)!, section: path.section);
print(indexPath)
self.communityTableView.beginUpdates();
self.communityTableView.insertRows(at: [indexPath], with: .automatic);
self.communityTableView.endUpdates();
//self.communityTableView.reloadRows(at: [indexPath], with: .automatic);
}
Но ответ «Неверный»update: недопустимое количество строк в разделе 0. Количество строк, содержащихся в существующем разделе после обновления (4), должно быть равно количеству строк, содержащихся в этом разделе до обновления (1), плюс или минус числостроки, вставленные или удаленные из этого раздела (1 вставлено, 0 удалено) ... "
Я знаю, что numberOfRows ожидает 4 строки, но почему insertRows пытается вставить только одну, когда следует вставить 3 строки?