- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 3 个部分(服务、可用性和天数)的 TableView ,每个部分中有多个行。我实现了一个,以便在选择任何行时看到复选标记。现在,我想在第一次关闭表格后再次显示表格时再次看到选定的行。就像显示所选项目的历史记录一样。
这是显示复选标记的代码:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indPath = indexPath
let section = indPath.section
switch section {
case 0:
updateCell(indPath, select: true)
case 1:
updateCell(indPath, select: true)
case 2:
updateCell(indPath, select: true)
default:
Void()
}
}
override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
let indPath = indexPath
let section = indPath.section
switch section {
case 0:
updateCell(indPath, select: false)
case 1:
updateCell(indPath, select: false)
case 2:
updateCell(indPath, select: false)
default:
Void()
}
}
func updateCell(indexpath: NSIndexPath, select: Bool) {
if let cell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: indexpath.row, inSection: indexpath.section)) {
if select{
cell.accessoryType = .Checkmark
}
else {
cell.accessoryType = .None
}
}//end if cell
现在是我从所选行获取数据的方法:
func save(){
if let indexPaths = self.tableView.indexPathsForSelectedRows{
for indexPath in indexPaths{
switch indexPath.section{
case SectionIndex.Services.rawValue:
switch indexPath.row{
case ServicesIndex.Recieve.rawValue:
selectedServices.insert("RECEIVE")
case ServicesIndex.Send.rawValue:
selectedServices.insert("SEND")
default:
Void()
}//end switch
case SectionIndex.Availability.rawValue:
switch indexPath.row{
case AvailabiltiyIndex.Morning.rawValue:
selectedAvailabilities.append(6.0...9.0)
case AvailabiltiyIndex.Regular.rawValue :
selectedAvailabilities.append(9.0...18.0)
case AvailabiltiyIndex.Evening.rawValue:
selectedAvailabilities.append(18.0...21.0)
default:
Void()
}//end switch
case SectionIndex.Days.rawValue:
switch indexPath.row{
case DaysIndex.Sunday.rawValue:
selectedDays.insert("Sunday")
case DaysIndex.Monday.rawValue:
selectedDays.insert("Monday")
case DaysIndex.Tuesday.rawValue:
selectedDays.insert("Tuesday")
case DaysIndex.Wednesday.rawValue:
selectedDays.insert("Wednesday")
case DaysIndex.Thursday.rawValue:
selectedDays.insert("Thursday")
case DaysIndex.Friday.rawValue:
selectedDays.insert("Friday")
case DaysIndex.Saturday.rawValue:
selectedDays.insert("Saturday")
default:
Void()
}//end switch
default:
Void()
}//end switch
}//end for
}//end If
}//end save
最佳答案
表格 View 关闭后,选择状态本身就会丢失。如果不关心它,它只是 View 管理的状态的一部分。
在您的 save
方法中,您正在存储“选择状态”。您可以使用这些 selectedServices
、selectedAvailities
和 selectedDays
变量来存储选择状态。如果第二次显示 TableView 时仍然有这些,您可以从中提取选择状态。
您可能会从此更改 updateCell 调用:
updateCell(indPath, select: false)
对此:
updateCell(indPath, select: selectionState(indPath))
并定义一个像这样的方法:(注意selectedServices.contains("RECEIVE")
)
func selectionState(indexpath: NSIndexPath) -> Bool {
let indPath = indexPath
let section = indPath.section
switch section {
case 0:
switch indexPath.row{
case ServicesIndex.Recieve.rawValue:
return selectedServices.contains("RECEIVE")
...
case 1:
updateCell(indPath, select: false)
case 2:
updateCell(indPath, select: false)
default:
Void()
}
}
contains 方法实际上从数据模型中提取选择状态(这些实例由 selectedServices
等引用)。如果无法实现 contains
方法,您可能必须创建一个仅存储选择状态的数据结构。然后,您从该数据结构中读取选择状态,并将选择状态写入数据结构和 selectedServices
等实例。
关于ios - 在 swift 中关闭 tableView 后再次查看复选标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33057299/
之前有人问过这个问题,但是当移动到具有相反字节序的平台(在这种情况下从大到小)时,我仍然对如何处理位域结构感到有些困惑。所以如果我有这个: typedef struct { unsigned
我之前问过这个问题here , 但它被标记为重复并已关闭。不幸的是,我被指出的答案不起作用.... 所以,再次: 我可以生成一个像这样的 eCharts4r 仪表 library(echarts4r)
关于 .NET 中对不可为空引用类型的支持存在很多问题。最大的希望是代码契约,但它仅限于对预算有限的人进行运行时检查。 对于代码契约以外的方法,Jon Skeet 写了一篇 blog post几年前,
当我通过将终止标志设置为true来停止线程'srch_slave_thread'时,(srch_slave_thread.terminate)释放线程的线程停止在析构函数的'inherited'行中,
We know that Windows 使用 CR + LF 对作为换行符,Unix(包括 Linux 和 OS X)使用单个 LF,而 MacOS 使用单个 CR。 这是否意味着 C 和 C++
This other SO question询问 WPF 中的自动完成文本框。有几个人已经构建了这些,其中给出的答案之一表明 this codeproject article . 但我还没有找到任何与
这个问题对我来说就像是噩梦的重演。该项目是使用 gpt3 训练聊天机器人,我正在试验嵌入。 我有文档,我正在尝试为不同的部分创建嵌入。根据我的测试,getEmbeddings() 似乎返回了一个值。但
我收到数据读取器初始化错误。我知道这个问题以前已经回答过很多次了,但这些案例似乎不适合我的情况。错误消息开头为“执行读取器:连接属性尚未初始化。” 程序: using System; using Sy
我知道这个问题已被多次询问和回答,但我正在抓狂,因为所提出的解决方案似乎都不起作用。 尽管有一个有效的配置文件,据我所知,它与 bundle 标识符匹配,但我收到了上述错误: 我已按照本网站上各种建议
所以我有一个小问题 这是我的文字 AFTER_2011/03/01 GREATER_2004_NOT 我想要 AFTER 和 GREATER,所以我有以下正则表达式: [A-Z]{2,}\\B 一开始
这个问题对我来说就像是噩梦的重演。该项目是使用 gpt3 训练聊天机器人,我正在试验嵌入。 我有文档,我正在尝试为不同的部分创建嵌入。根据我的测试,getEmbeddings() 似乎返回了一个值。但
我目前正在做具有图形功能的计算器应用程序。然后,我在我的计算器中有这个按钮,并将它连接到我的 Calculator2ViewController 上。此外,我将此按钮连接到另一个名为 GraphVie
昨天,我尝试以一种方式执行此操作...今天我尝试另一种方式,但仍然卡住了。我必须找到一种使用整数除法和取模来做到这一点的方法。这是我的代码,后面是错误消息。 public int evaluateFr
我大致正在处理以下内容: var i; var k = 5; $('document').ready(function () { $('#someElement').click(functio
又是realloc的问题。看来我在之前的很多realloc语句中都没有发现类似的问题。我将不胜感激您的兴趣。 我正在尝试读取格式的文本输入: g:;0,1,0,1,0 。我在源文本文件中有一组这种格式
我不知道为什么下面会给我:*“error LNK2001: unresolved external symbol 'struct Win32Vars_t win32' (?win32@@3UWin32
又是我。在我所有的问题中,我认为这是所有问题中最愚蠢的,但由于疲劳或愚蠢,我也需要一些帮助。然而,最重要的是,我这样做是为了我的一项任务,并且有一个严格的规则 - 我必须使用一个函数调用 char*
在 Ubuntu 14.04.5 上运行 MySql 5.5.53。当从文本文件导入数据时(加载数据 infil $FIL INTO TABLE &c),我收到可怕的提示,因为 secure_file
我在 Stackoverflow 中找到了大量关于如何选择组中第一行和最后一行的示例,但我无法根据需要调整它们。唉,我对 MySQL 的有限了解无济于事。 一些数据(date_time、val1 和
我遇到错误“连接必须有效并再次打开,当我更改我的 sql 查询代码时。任何人都可以帮忙吗??(编辑)在 form1 中我已经连接到数据库,在 form2 中我试图添加查询。 //IN Class1.c
我是一名优秀的程序员,十分优秀!