问题描述
我正在尝试在Pod文件SpreadsheetView中设置列标题和行标题。我正在尝试使用我的标题数组设置列标题和行标题,并且我已经成功获取了列标题设置。但是,现在我无法调用同一函数来对行标题执行相同的操作。
此函数设置了它们,但是它当然不能被两次调用: Buuuut,因为我是菜鸟,并且会尝试任何随机操作,所以我将该函数重命名为电子表格ViewII,但这并不可行。我的数组未与代码链接或其他错误吗?再次回到原始问题...
ciphertext
这是我的基本菜鸟问题和困惑。 如何设置两个页眉,然后又在工作表中添加值?
func spreadsheetViewII(_ spreadsheetView: SpreadsheetView,cellForItemAt indexPath: IndexPath) -> Cell? {
let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: MyLabelCell.identifier,for: indexPath) as! MyLabelCell
cell.setup(with: "Cell")
cell.backgroundColor = .clear
if indexPath.section == 0 {
cell.setup(with: rowHeaders[indexPath.row])
}
return cell
}
解决方法
我在函数内部使用了一个if开关来处理这个问题。
func spreadsheetView(_ spreadsheetView: SpreadsheetView,cellForItemAt indexPath: IndexPath) -> Cell? {
let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: MyLabelCell.identifier,for: indexPath) as! MyLabelCell
cell.setup(with: "Cell")
cell.backgroundColor = .clear
if case 0 = indexPath.row {
cell.setup(with: columnHeaders[indexPath.section])
return cell
} else if case 0 = indexPath.section {
cell.setup(with: rowHeaders[indexPath.row])
return cell
}
return cell
}