【发布时间】:2015-08-25 19:10:09
【问题描述】:
在我的代码中,我有一个表格视图,可以加载使用我的应用程序的用户名。当用户选择一行时,它将出现一个复选标记。我想要做的是保存一个包含所有选定行的数组(该数组将包含名称)。找了一些资料,但是我还在学iOS编程,不懂Obj-c。
这是我到目前为止所做的:
var selectedMembers = [String]?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.names?.count ?? 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("UserCell") as! UITableViewCell
cell.textLabel!.text = names![indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
selectedMembers = Array()
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .Checkmark
{
cell.accessoryType = .None
self.selectedMembers?.remove(indexPath)
}
else
{
cell.accessoryType = .Checkmark
self.selectedMembers?.append(indexPath)
}
}
}
【问题讨论】:
-
看看这个问题,是关于如何将 Swift 数组保存到文件 stackoverflow.com/questions/24977139/…
-
您的问题是如何保存数组以备后用或如何获取所选成员的名称(行中的字符串)
-
@milo526 我将使用这些名称(保存在数组中)来创建一个组。
标签: ios arrays swift uitableview