如何将表格单元格中的数据移动到swift中的另一个表格单元格?

时间:2017-11-24 06:13:47

标签: swift4

我说英语不好。请轻松回答。 我正在迅速做笔记。但是有一些问题。 我想像Window一样制作回收站功能。 所以我想将表Stack<Integer> s = new Stack<>();中的数据移到另一个表cell(Main.View)

enter image description here

单击主视图中标签旁边的图标,打开一个窗口,要求您将其删除。 如果我要删除它,表cell(TrashCan.View)中的数据会移到另一个表cell(Main.View)

cell(TrahshCan.View)

此代码是 @IBAction func actionSheet(_ sender: Any) { let alertController = UIAlertController(title: "Hello", message: "What do you want to do?", preferredStyle: .actionSheet) let lockAction = UIAlertAction(title: "Lock", style: .destructive) { (action: UIAlertAction) in } let deleteAction = UIAlertAction(title: "Delete", style: .destructive) { (action: UIAlertAction) in print("delete") func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if (segue.identifier == "targetSegue"){ let trashView : TrashCan = segue.destination as! TrashCan trashView.MemoData = self.MemoData } } } // Main의 delete는 지우기가 아닌 휴지통으로 이동을 의미함 let cancelButtonAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) alertController.addAction(lockAction) alertController.addAction(deleteAction) alertController.addAction(cancelButtonAction) present(alertController, animated: true, completion: nil) } 中的操作表(三行三元组图标)

,接下来是Main.View(回收站)

TrashCan.View

我该如何解决这些问题?拜托,帮帮我T.T

1 个答案:

答案 0 :(得分:0)

您已经在trashView对象类中传递了MemoData。现在您需要使用该MemoData并在trashView上显示。

更新: 首先将备忘录数据存储到UserDefault。从这里更新代码

@IBOutlet weak var trashView: UITableView!

var MemoData = [String]()

override func viewDidLoad() {
super.viewDidLoad()

 if let MemoData = UserDefaults.standard.array(forKey: "MemoData")) {
    print(MemoData)
}

   // Do any additional setup after loading the view.
}

// MARK : Table
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -
> Int {
    return MemoData.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> 
UITableViewCell {

    let Cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TrashCell
    Cell.TitleLabel.text = MemoData[indexPath.row]

   return Cell
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{
    let MemoNumber = indexPath.row
    UserDefaults.standard.set(MemoNumber, forKey: "MemoNumber")

    self.performSegue(withIdentifier: "ToRecord", sender: self)
}
// Table_End

@IBAction func trashList(_ sender: Any) {
    let alertController = UIAlertController(title: "Hello", message: "What do you want to do?", preferredStyle: .actionSheet)

    let moveAction = UIAlertAction(title: "Move", style: .destructive) { (action: UIAlertAction) in

 } // Main으로 복원

    let deleteAction = UIAlertAction(title: "Delete", style: .destructive) { (action: UIAlertAction) in

  } // 완전삭제

    let cancelButtonAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel)


    alertController.addAction(moveAction)
    alertController.addAction(deleteAction)
    alertController.addAction(cancelButtonAction)
    present(alertController, animated: true, completion: nil)
}
}

现在从UserDefault获取“MemoData”并在TrashView上显示

Users
-----

id, firstname, lastname, in_groups
----------------------------------

1, Jake, New house, [1]

35, Gavin, McInnes, [1, 32, 41]  

Groups
------

id, group_name, group_password, total
--------------------------------------------

1, Destroyers, password, 1

32, Gamers, password, 41

41, Media, password, 22

这会有所帮助。