gpt4 book ai didi

ios - 滚动 UITableView 时复选标记消失

转载 作者:行者123 更新时间:2023-11-28 11:06:56 28 4
gpt4 key购买 nike

正如标题所说,我的复选标记正在消失。我找到的答案只是对特定代码的修复,所以我不确定我的问题是什么。

如有任何帮助,我们将不胜感激。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellx: UITableViewCell = self.tableViewOut.dequeueReusableCellWithIdentifier("cellx", forIndexPath: indexPath)



// Configure the cell...

switch (indexPath.section) {


case 0:
cellx.textLabel?.text = "\(qUnitArray[indexPath.row])\t\t\t\(functionList.searchUnitCount(ttopicArray, funitSearch: qUnitArray[indexPath.row])) \t \(functionList.searchUnitRating(ttopicArray, fDataStore: tDataStore, funitRating: qUnitArray[indexPath.row]))"
cellx.accessoryType = .None
conUnit = qUnitArray[indexPath.row]

conUnitCount = 0
while conUnitCount < selectedUnit.count {
if selectedUnit[conUnitCount] == qUnitArray[indexPath.row] {
cellx.accessoryType = .Checkmark
print("checkmark change")
}
conUnitCount += 1
}
case 1:
cellx.textLabel?.text = "\(qsubjectArray[indexPath.row])\t\t\t\(functionList.searchSubjectCount(ttopicArray, fsubjectSearch: qsubjectArray[indexPath.row])) \t \(functionList.searchSubjectRating(ttopicArray, fDataStore: tDataStore, fsubjectRating: qsubjectArray[indexPath.row]))"
cellx.accessoryType = .None
conSubject = qsubjectArray[indexPath.row]

conSubjectCount = 0
while conSubjectCount < selectedSubject.count {
if selectedSubject[conSubjectCount] == qsubjectArray[indexPath.row] {
cellx.accessoryType = .Checkmark
print("checkmark change")

}
conSubjectCount += 1
}
default:
cellx.textLabel?.text = "Other"

}






func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let cellx = tableView.cellForRowAtIndexPath(indexPath) {
if cellx.accessoryType == .Checkmark
{
cellx.accessoryType = .None

if indexPath.section == 0 {
while tempUnitCount < tselectedArray[0].count {
if qUnitArray[indexPath.row] == tselectedArray[0][tempUnitCount] {
tempUnitCode = tempUnitCount
}
tempUnitCount += 1
}
tselectedArray[0].removeAtIndex(tempUnitCode)
tempUnitCode = 0
tempUnitCount = 0
} else {
while tempSubjectCount < tselectedArray[1].count {
if qsubjectArray[indexPath.row] == tselectedArray[1][tempSubjectCount] {
tempSubjectCode = tempSubjectCount
}
tempSubjectCount += 1
}

tselectedArray[1].removeAtIndex(tempSubjectCode)
tempSubjectCode = 0
tempSubjectCount = 0
}
}
else {
cellx.accessoryType = .Checkmark

if indexPath.section == 0 {
if tselectedArray[0] == [""] {
tselectedArray[0][0] = qUnitArray[indexPath.row]
} else {
tselectedArray[0].append(qUnitArray[indexPath.row])
}
}else {
if tselectedArray[1] == [""] {
tselectedArray[1][0] = qsubjectArray[indexPath.row]
} else {
tselectedArray[1].append(qsubjectArray[indexPath.row])
}
}
}
}

最佳答案

不要在此方法中设置 accessoryType。不要在此处以任何方式更改单元格。

根据需要从 cellForRowAtIndexPath: 获取单元格,并且重复使用相同类型的单元格。因此,更改数据源中的某些内容以使其知道新状态并调用其中一个 tableView 重新加载函数以使其重新制作单元格。

当您的单元格滚动关闭然后重新打开时,它将调用 cellForRowAtIndexPath: -- 您正在更改的单元格不是对表格的永久更改。

关于ios - 滚动 UITableView 时复选标记消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37036113/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com