我试图在搜索视图和非搜索视图之间同步accessoryType.Checkmark。我尝试将cell.accessoryType = .None设置在cellForRowAtIndexPath上的几个不同的位置,但是当我在fetchedResults和搜索结果之间切换时,我仍然会得到随机的检查点。我不知道我搞砸了什么,但我可以放心,这会是一件令人吃惊的蠢事。
我有一个设置好的UITableViewController。当它加载时,我将它配置为显示来自NSFetchRequest的项。它工作得很完美。
我也设置了一个UISearchController。它工作得很完美,并显示了我想要的结果。
当我在搜索和fetchRequest之间切换时,我遇到了随机检查点的问题。我要保存的东西数组工作得很好,正确的项目也在里面如有任何反馈,将不胜感激。我没有主意了。
下面是我在viewDidLoad类中在UITableViewController类中声明的相关属性:
// Create array to dump fetchResults
var unfilteredJingles = [Jingle]()
// Create array to store filtered search results
var filteredJingles = [Jingle]()
// Array where ones I want to save get added/removed
var jinglesToSave = [Jingle]()
// resultsSearchController
var resultsSearchController = UISearchController()当选择单元格时,我已经将didSelectRowAtIndexPath配置为做两件事:
1)将该单元格的jinglesToSave附加到数组中,并在单元格旁边放置一个复选标记。这个很管用。
2)从jinglesToSave数组中删除该单元格的jinglesToSave。这个也能用。
我遇到的问题是,当我在searchResultsController.active和searchResultsController之间切换时,随机单元会被检查,而不是活动的。正确的细胞会被检查,但随机的细胞有时会被检查。
这是我的cellForRowAtIndexPath
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("jingleCell", forIndexPath: indexPath)
// instantiate a local array and assign it to filtered/unfiltered results based on whether
// the resultsSearchController is active
var jingleArray = [Jingle]()
if resultsSearchController.active {
// set local array to the filtered array
jingleArray = filteredJingles
let jingle = jingleArray[indexPath.row]
// Set labels for cell
cell.textLabel?.text = jingle.jingleDescription
cell.detailTextLabel?.text = jingle.jingleStar
} else {
// set the local array to the UN-filtered array
jingleArray = unfilteredJingles
// Get the jingle for the index
let jingle = jingleArray[indexPath.row]
// Set labels for cell
cell.textLabel?.text = jingle.jingleDescription
cell.detailTextLabel?.text = jingle.jingleStar
}
// Set checkmarks
if self.jinglesToSave.count > 0 {
// enumerate jinglesToSave...
for (indexOfJinglesToSave, jingleToSave) in jinglesToSave.enumerate() {
// if the object in the array of stuff to save matches the object in the index of the tableview
if jingleArray[indexPath.row].hashValue == jinglesToSave[indexOfJinglesToSave].hashValue {
// then set its accessoryView to checkmark
cell.accessoryType = .Checkmark
}
}
}
return cell
}发布于 2015-10-15 05:03:14
在单元格去队列后,将单元格复选标记状态重置为默认状态(im猜测没有复选标记)。这可能是一个细胞循环的问题,它的标记出现在细胞上,它不应该在上面。
https://stackoverflow.com/questions/33140167
复制相似问题