ios - numberOfSectionsInTableView 未调用

标签 ios uitableview swift

在我的 ViewController 中,我有一个 UITableView 和这些方法:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    if(self.mQuoteObjects.count > 0){
        return 1
    }
    return 0

}


func tableView(tableView: UITableView, numberOfSectionsInTableView section: Int) -> Int {
    let nbItem = self.mQuoteObjects.count
    return nbItem

}

方法“numberOfRowsInSection”被正确调用,但“numberOfSectionsInTableView”从未被调用。

我错过了什么?

你可以在 Obj-c 中响应

最佳答案

方法名称不正确。它应该是 numberOfSectionsInTableView(_:)

参见 UITableViewDataSource protocol reference .

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return self.mQuoteObjects.count
}

关于ios - numberOfSectionsInTableView 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29803132/

相关文章:

swift - 如何保存 UIImage 进行解析

ios - 如何使用 int 值将项目添加到 TableView

ios - 将实时照片集成到我的应用程序中

ios - 将 UITableView 连接到 UIView 错误

ios - 在代码中以编程方式更改 TableView 大小

ios - SwiftyJSON 未正确从文件初始化

ios - 延迟切换 View 更改

ios - 如何在 TableView 的每个部分中添加摘要条目

ios - Swift 3,使用带有闭包的函数扩展 Objective-C 泛型类

ios - 未返回 attributedText 的高度