我无法将新行添加到 tableViewCell 的顶部。 我创建一个函数并将其放置在 viewDidload 中,并刷新。删除函数重新加载数据。 我的代码:
刷新:
@objc func refreshing() {
insertNewRow()
loadObjects1()
loadObjects2()
loadObjects3()
tableView.reloadData()
refresh.endRefreshing()
}
解析:
func loadObjects1() {
let query = Soccer.query() as! PFQuery<Soccer>
query.findObjectsInBackground { (objects, error) in
if error == nil {
self.soccerString.removeAll()
self.soccerString = objects!
self.tableView.reloadData()
} else {
print(error!)
}
}
}
添加新行顶部:
func insertNewRow() {
soccerString.append(Soccer())
tableView.beginUpdates()
soccerString.insert(Soccer(), at: 0)
tableView.insertRows(at: [IndexPath(row:0, section:0)], with: .automatic)
tableView.endUpdates()
}
最佳答案
insertNewRow
不起作用,因为您要添加两个 个新项目,一个位于顶部 (insert(...
),另一个位于顶部在底部(append(...
)),但在表格 View 中仅插入一行行。
这就足够了
func insertNewRow() {
soccerString.insert(Soccer(), at: 0)
tableView.insertRows(at: [IndexPath(row:0, section:0)], with: .automatic)
}
关于ios - Swift(解析)顶部 UITableViewCell 的新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47050432/