使用集合配置 TableView 单元格
Configure TableView Cells With A Set
我不确定如何配置我的自定义单元格以使用 tableView 中的集合。我希望能够显示我的单元格,但出现语法错误 无法在我的 cellForRowAt 中使用我的 itemFav 调用非函数类型 'Set' 的值,我将如何配置我的当前索引使用集合?
var favSet = Set<CurrentPlayers>()
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "favcell", for: indexPath) as! FavCell
let itemFav = favSet(indexPath.row) //How do I configure this to a set
cell.update(with: itemFav)
return cell
}
据我了解,您需要按索引访问。试试这个:
favSet[favSet.index(favSet.startIndex, offsetBy: indexPath.row)]
我不确定如何配置我的自定义单元格以使用 tableView 中的集合。我希望能够显示我的单元格,但出现语法错误 无法在我的 cellForRowAt 中使用我的 itemFav 调用非函数类型 'Set' 的值,我将如何配置我的当前索引使用集合?
var favSet = Set<CurrentPlayers>()
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "favcell", for: indexPath) as! FavCell
let itemFav = favSet(indexPath.row) //How do I configure this to a set
cell.update(with: itemFav)
return cell
}
据我了解,您需要按索引访问。试试这个:
favSet[favSet.index(favSet.startIndex, offsetBy: indexPath.row)]