【发布时间】:2018-01-14 08:54:51
【问题描述】:
在某些情况下:tableView 有不止一种类型的 UItableViewCell,并且这些单元格实现了函数“setData(_:)”。 所以,在
"tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell".
我可以使用
"perfrom(selector:)"
避免“快速类型转换(如if indexPath.row == 1{ cell as! SomeCoustomCell })".
但如果我使用
"#selector()"
我仍然需要知道细胞类型并使用
"SomeCoustomCell.setData(_:)".
因此,我通过使用解决了它
"cell.perform(Selector("setData:"), with: dataSource[indexPath.row]["data"])"
虽然它有一个警告。
swift中的正确方法是什么??
【问题讨论】:
标签: ios uitableview dynamictype