【发布时间】:2018-08-15 09:01:05
【问题描述】:
我正在尝试通过tableView 中的每个cell iterate 使用amountValue 值进行计算。
我写了一个工作方法迭代tableView而不是data source,你们有些不高兴哈哈。
如何将其转换为 data source 迭代?
// CryptosMO is the Managed Object with an `NSNumber` `amountValue` attribute among others.
var item : [CryptosMO] = []
if CDHandler.fetchObject() != nil {
item = CDHandler.fetchObject()
}
for section in 0...self.tableView.numberOfSections {
if (self.tableView.numberOfRows(inSection: section) > 1) {
for row in 0...self.tableView.numberOfRows(inSection: section) {
let indexPath: IndexPath = IndexPath(row: row, section: section)
if item[indexPath.row].amountValue != nil {
let total = item[indexPath.row].amountValue.doubleValue + item[indexPath.row + 1].amountValue.doubleValue
print("TOTAL :", total)
}
}
}
}
【问题讨论】:
-
为什么要迭代 tableview 来获取总数?不是数据源?
-
@mnemonic23 感谢您的回答,这正是我想要做的。你能告诉我怎么做吗?
标签: swift function uitableview core-data datasource