Swift 使用集合配置TableView单元格
我不确定如何配置自定义单元格以在tableView中使用集合。我希望能够显示我的单元格,但在我的cellForRowAt和我的itemFav中出现语法错误无法调用非函数类型“Set”的值,我将如何配置我的当前索引以使用SetSwift 使用集合配置TableView单元格,swift,xcode,uitableview,Swift,Xcode,Uitableview,我不确定如何配置自定义单元格以在tableView中使用集合。我希望能够显示我的单元格,但在我的cellForRowAt和我的itemFav中出现语法错误无法调用非函数类型“Set”的值,我将如何配置我的当前索引以使用Set var favSet = Set<CurrentPlayers>() override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITa
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
}
var favSet=Set()
重写func tableView(tableView:UITableView,cellForRowAt indexath:indexPath)->UITableViewCell{
让cell=tableView.dequeueReusableCell(标识符为“favcell”,表示:indexPath)为!favcell
让itemFav=favSet(indepath.row)//如何将其配置为一个集合
cell.update(使用:itemFav)
返回单元
}
据我所知,您需要通过索引进行访问。试试这个:
favSet[favSet.index(favSet.startIndex,offsetBy:indexPath.row)]
您可能需要favSet[indexPath.row]
但这无法工作,因为集合是无序的。最好对数据源使用数组。首先找到与indexPath.row
关联的CurrentPlayer
对象,然后查看itemFav.contains(theAssociatedPlayer)
。您能解释一下为什么降级吗?