Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 使用集合配置TableView单元格_Swift_Xcode_Uitableview - Fatal编程技术网

Swift 使用集合配置TableView单元格

Swift 使用集合配置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

我不确定如何配置自定义单元格以在tableView中使用集合。我希望能够显示我的单元格,但在我的cellForRowAt和我的itemFav中出现语法错误无法调用非函数类型“Set”的值,我将如何配置我的当前索引以使用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
}
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)
。您能解释一下为什么降级吗?