[英]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.