我有一组字符串,其中包含一些数据。 但是,当我显示的数据从设置到tableView,在cellForRowAtIndexPath方法,它给了我上述的错误。 这里是我的代码:不能使用类型'Int'的索引对'Set <String>'类型的值进行下标
var tradeSet: Set<String> = ["TKAI", "YNDX", "PSTG"]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyTrade", forIndexPath: indexPath) as! MyTradeTableViewCell
let objects = tradeSet[indexPath.row]
cell.tradeName.text = objects
return cell
}
任何帮助将是伟大的。谢谢!
“集合”是一种无序的集合类型,不能通过索引对其进行下标。 – vadian
你必须将set转换为数组。 –
@vadian Well *技术上*它可以通过索引下标,只是一个'SetIndex',而不是'Int';) – Hamish