ios - Swift(解析)顶部 UITableViewCell 的新行?

标签 ios swift uitableview

我无法将新行添加到 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/

相关文章:

ios - addStateDidChangeListener后执行函数

ios - 带有根据用户输入更改标签的按钮的 TableView

ios - 在 xcode/swift 中使用位置管理器获取用户的当前位置时,我得到的值为 nil。有什么建议么?

ios - 如何从 UITableView 中的 Web 服务加载大量数据?

swift - 在 UITableView 中模拟 userScrolling

ios - 如何在 Swift 3 中的 map View 上生成不同的引脚?

ios - ZipArchive 跳过文件 49-100

ios - tableView.scrollToRow() 的替代品

iphone - scrollViewWillBeginDragging 中的滚动量

swift - 划分 UITableView 单元格 - 重复单元格