Ios Swift(Xcode 6.1 GM)-在didSelectRowAtIndexPath上设置附件类型未正确显示
当我运行此代码并点击一个单元格时,它总是将复选标记放在最底部的单元格上,如果我上下滚动表格视图,它会将其放在最顶部的单元格上。有什么想法吗Ios Swift(Xcode 6.1 GM)-在didSelectRowAtIndexPath上设置附件类型未正确显示,ios,xcode,swift,ios8,Ios,Xcode,Swift,Ios8,当我运行此代码并点击一个单元格时,它总是将复选标记放在最底部的单元格上,如果我上下滚动表格视图,它会将其放在最顶部的单元格上。有什么想法吗 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return resultsArray.count } func tableView(tableView: UITableView, cellForRowAtIndexPat
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return resultsArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
if (cell != nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
}
cell?.textLabel?.text = resultsArray[indexPath.row] as? String
return cell!
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println(indexPath.row)
if cell?.accessoryType != UITableViewCellAccessoryType.Checkmark {
cell?.accessoryType = UITableViewCellAccessoryType.Checkmark
} else if cell?.accessoryType == UITableViewCellAccessoryType.Checkmark {
cell?.accessoryType = UITableViewCellAccessoryType.None
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
倒数第二种方法中的细胞来自哪里?你在用手机?很多在cellForIndex方法中,它应该是一个局部变量;您看起来像是在实例级别定义它,这解释了您看到的行为。这里有一个线程可能有用:啊哈!我确实将它声明为一个实例变量,这样我就可以在didSelectRow方法中再次使用它,这让我觉得我用错了。谢谢你,我会研究如何正确地做到这一点。我真的很想运行一些基于行是否被选中的代码,这实际上很好,只是到处都是复选标记-再次感谢!