tl; dr:我无法弄清楚如何从我的NewTransactionViewController返回到我的主CollectionViewController,并且在返回时,将NewTransactionViewController中的数据添加到我的集合列表视图中。我在网上找到的内容不是我所需要的就是太基本,就是太复杂。基本上我试图模仿一个UITableView,但我稍后使用更多动态功能的集合(加上我想要多列选项)。如何保存数据并返回集合视图?
我是新来的编程,正在尝试设置一个简单的预算应用程序来记录事务。目标是让用户通过填写详细信息并单击“保存”来添加新事务,然后返回到前一个VC并添加这些详细信息并更新收集视图。
在此先感谢您的帮助!
// ViewController.swift
import UIKit
class NewTransactionViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate
{
//Add new transaction cell to master list
@IBAction func addNewTransaction(_ sender: UIBarButtonItem)
{
//Unsure how to implement
}
class CollectionViewController: UICollectionViewController
{
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as UICollectionViewCell
let categoryLabel = cell.viewWithTag(1) as! UILabel
categoryLabel.text = categoryArray[indexPath.row]
let balanceLabel = cell.viewWithTag(2) as! UILabel
balanceLabel.text = balanceArray[indexPath.row]
return cell
}
}
感谢您的参考。有助于从该POV中思考它。 – naomijp