在我的代碼中,我有一個表格視圖來加載使用我的應用程序的用戶的名稱。當用戶選擇一行時,它會顯示一個複選標記。我想要做的是保存一個包含所有選定行的數組(該數組將包含名稱)。我發現了一些信息,但我仍然在學習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 - 將數組寫入文本文件]的可能重複(http://stackoverflow.com/questions/24977139/swift-write-an-array-to-a-text-file) –
只需檢查此內容問,是關於如何將斯威夫特數組保存到一個文件http://stackoverflow.com/questions/24977139/swift-write-an-array-to-a-text-file –
是你的問題如何保存爲陣稍後使用或如何獲取選定成員的名稱(行中的字符串) – milo526