Я взял здесь очень простую часть кода, чтобы продемонстрировать лишь одну из нескольких проблем, которые я использую UITabelView.Во-первых, когда вы помещаете в таблицу некоторые тестовые данные, которые возвращаются тремя массивами topicListOne, topicListTwo и т. Д. Так что эта часть работает нормально, но в переопределении, когда ячейки сняты, секция пути индекса вернулась к нулю.Я установил все соответствующие переопределения для обработки таблицы, т. Е. Возвращает количество разделов, возвращает количество элементов в каждом разделе и т. Д. Кто-нибудь видел что-то странное раньше?Я использовал аналогичный подход с более ранним проектом, и все это работало нормально.
self.topicListOne.append("test1")
self.tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
self.topicListOne.append("test2")
self.tableView.insertRows(at: [IndexPath(row: 0, section: 1)], with: .automatic)
self.topicListOne.append("test3")
self.tableView.insertRows(at: [IndexPath(row: 0, section: 2)], with: .automatic)
попробовал отладку и почти все, но все, что происходит, не очевидно извне.
см. Код в вопросе, но я также добавил несколько строк из метода dequeue идругие переопределения:
extension ViewControllerFive {
override func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section
{
case 0:
return topicListOne.count
case 1:
return topicListTwo.count
case 2:
return topicListThree.count
default:
fatalError()
}
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 20
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let animation = AnimationFactory.makeSlideIn(duration: 0.5, delayFactor: 0.05)
let animator = AnimatorManager(animation: animation)
animator.animate(cell: cell, at: indexPath, in: tableView)
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 70
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell
cell.layer.cornerRadius = 5
cell.layer.masksToBounds = true
cell.labelOne.text = "Topic:"
print("Index row: ", indexPath.row)
print("Index sec: ", indexPath.section)
switch (indexPath.section) {
case 0:
cell.labelTwo.text = topicListOne[indexPath.row]
case 1:
cell.labelTwo.text = topicListTwo[indexPath.row]
case 2:
cell.labelTwo.text = topicListThree[indexPath.row]
default:
fatalError()
}
cell.labelOne.layer.cornerRadius = 5
cell.labelOne.layer.masksToBounds = true
cell.labelTwo.layer.cornerRadius = 5
cell.labelTwo.layer.masksToBounds = true
cell.contentView.layer.cornerRadius = 20
cell.contentView.layer.masksToBounds = true
/*
cell.contentView.viewWithTag(5)?.layer.cornerRadius = 10
cell.contentView.viewWithTag(5)?.layer.masksToBounds = true
*/
cell.isUserInteractionEnabled = false
return cell
}
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section
{
case 0:
return "Trending News To Comment On"
case 1:
return "User Topics"
case 2:
return "Private Messages"
case 3:
return "Archived News Stories"
default:
return "Not Set"
}
}
сообщений об ошибках как таковых нет, но в представлении отображаются три результата теста, все в первом разделе.Есть и другие проблемы, которые связаны с тем, что у меня также установлен список-лист firebase, и эти результаты, похоже, никуда не денутся, но, возможно, это должен быть отдельный вопрос.Любая помощь от экспертов IOS Swift там высоко ценится?