【发布时间】:2018-01-13 16:41:10
【问题描述】:
我正在开发可扩展的 tableView,我需要在其中添加或删除基于 didSelectRowAtIndexpath 的对象。我能够将所选项目添加到数组中,但问题是当我尝试从数组中删除选择时。
这是我得到的错误:
无法使用 (of:any) 类型的参数列表调用索引
这是我的代码:
func expandableTableView(_ expandableTableView: LUExpandableTableView, didSelectRowAt indexPath: IndexPath) {
let selectedService = arrData[indexPath.section].Children?[indexPath.row].EnglishName ?? ""
let inPrice = arrData[indexPath.section].Children?[indexPath.row].InPrice ?? 0
print("service and price : \(selectedService) \(inPrice)")
let selectedItem = (" \(selectedService) \(inPrice)")
let cell: UITableViewCell? = expandableTableView.cellForRow(at: indexPath)
if cell?.accessoryType == UITableViewCellAccessoryType.none
{
cell?.accessoryType = UITableViewCellAccessoryType.checkmark
selectionArr.append(selectedItem)
}
else
{
cell?.accessoryType = UITableViewCellAccessoryType.none
selectionArr.remove(at: selectionArr.index(of: selectedItem)!)
}
print(selectionArr)
}
【问题讨论】:
-
selectionArr是什么类型? -
var selectionArr = [Any]()
-
[Any]导致问题。将selectionArr声明为更具体的内容。它似乎是一个字符串数组,所以[String].
标签: ios arrays swift uitableview swift3