简体   繁体   English

正在将数据从UITableView单元传送到另一个VC的tableview? (迅速)

[英]Carrying on data from a UITableView cell to another VC's tableview? (Swift)

I'm currently working on a project in swift where I have created a ViewController which has a UITableView. 我目前正在快速处理一个项目,在该项目中我创建了一个具有UITableView的ViewController。

http://prntscr.com/5wft7u http://prntscr.com/5wft7u

This UITableView you can swipe to delete. 您可以滑动此UITableView进行删除。 I'm wanting to make a 'Deleted items' or 'Recycle bin' section kind of thing on my other view where once the delete button is pressed it deletes from the first tableView and is now inserted into the 'Deleted items' view tableview cell. 我想在其他视图上制作“已删除邮件”或“回收站”部分的东西,一旦按下删除按钮,它将从第一个tableView中删除,现在插入到“已删除邮件”视图tableview单元中。

*Edit: *编辑:

I've been thinking, I would make another array for the recycled items. 我一直在想,我将为回收的物品制作另一个阵列。 In the UITableViewRowAction handler for deleting items, once you remove something out of your projects array, you add it to your recycled array. 在用于删除项目的UITableViewRowAction处理程序中,一旦从项目数组中删除了某些内容,便将其添加到回收的数组中。 Then pass that recycled array over to the other VC in prepareForSegue method, and the other VC will load that array into the table. 然后,在prepareForSegue方法中将该回收的数组传递给另一个VC,另一个VC将把该数组加载到表中。

I cant get this too work.. can someone please show me the code? 我也无法正常工作..有人可以告诉我代码吗?

First view code: pastebin.com/dBucJ9w0 View: prntscr.com/5wft7u 第一个视图代码:pastebin.com/dBucJ9w0视图:prntscr.com/5wft7u

The second view code is just a default VC class. 第二个视图代码只是默认的VC类。 The view for the second class is only a TableView. 第二类的视图只是一个TableView。

Thanks. 谢谢。

Add another array to each of your ViewControllers. 将另一个数组添加到每个ViewController。 First VC: Add var deleted: [String] = [] after your projects declaration. 第一个VC:添加var deleted: [String] = []projects声明后deleted: [String] = [] Then do this: 然后执行以下操作:

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == UITableViewCellEditingStyle.Delete {
        deleted.append(projects[indexPath.row])
        projects.removeAtIndex(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
    }
}

Finally make a prepareForSegue function to pass the data: 最后制作一个prepareForSegue函数来传递数据:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "YourIdentifier" {
        let destination = segue.destinationViewController as YourSecondViewControllerClass
        destination.arrayThatYouAdded = deleted
   }
}

And then just display the arrayThatYouAdded property in your second view controller however you would like in a table view. 然后只在第二个视图控制器中显示arrayThatYouAdded属性,但是您希望在表视图中显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从UITableView单元传递到另一个VC的UITableView? (迅速) - Passing data from a UITableView cell to another VC's UITableView? (Swift) 如何从多个选定的行中获取数据并在另一个VC tableview单元格Swift4中显示 - How to get data from the multiple selected rows and show in another VC tableview cell Swift4 从自定义tableview单元获取数据到另一个VC? - Getting data from custom tableview cell to another VC? 如何将数据从 TableView 单元格传递到 Swift 5 中的另一个 viercontroller? - How to pass data from TableView cell to another viercontroller in Swift 5? 将具有某些属性的核心数据从TableView中的选定单元格传递到另一个VC - Passing core data from selected cell in tableview with certain attributes to another VC 如何在另一个 VC2 的 `audioPlayerDidFinishPlaying()` 中重新加载 VC1 的 tableView 数据 - How to reload VC1's tableView data in another VC2's `audioPlayerDidFinishPlaying()` iOS如何将单元格数据发送到另一个VC使用Parse Swift - iOS How to send cell data to another VC use parse Swift 通过2个类/委托控制另一个单元格中UITableView单元格的内容 - control the content of UITableView cell from another cell with 2 classes / delegates Swift 将数据从单元格中的按钮传递到另一个表格视图? - passing data from button in cell to another tableview? Swift:当用户点击Tableview单元格时,如何将数据从一个视图控制器转移到另一个 - Swift: How to SHIFT data from one view controller to another when the user taps on the Tableview Cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM