我正在制作一个基本的健身应用程序,其中我有一个食物日记,可以跟踪你每天吃的食物。我有一个模式弹出窗口(下图),当您点击“添加食物”时会显示。当按下“保存到食物日记”按钮时,我无法从模式弹出窗口中插入行。我还尝试将卡路里标签更新为用户全天累积的当前卡路里。这是我到目前为止的代码:
class PopupVC: UIViewController {
var section: Int?
var caloriesLabel = " "
var tableData: [String] = [""]
let foodDiary = FoodDiary()
var caloriesCell = caloriesForDiary()
@IBOutlet weak var foodTimeLabel: UILabel!
@IBOutlet weak var foodPopup2: UIView!
@IBOutlet weak var foodPopUp: UIView!
@IBOutlet weak var inputFood: UITextField!
@IBOutlet weak var inputCals: UITextField!
@IBAction func saveToDiary(_ sender: Any) {
if (inputFood.text?.isEmpty)! || (inputCals.text?.isEmpty)! {
return
}
caloriesLabel = foodDiary.testVariable
tableData.append(inputFood.text!)
foodDiary.tableView.beginUpdates()
foodDiary.tableView.insertRows(at: [IndexPath.init(row: (tableData.count) - 1, section: section!)], with: .automatic)
foodDiary.tableView.endUpdates()
dismiss(animated: true, completion: nil)
}
基本上我正在尝试使用我的 PopUpVC 更新我的 FoodDiaryVC,并且我正在努力将两个控制器之间的数据传递给 insertRows 并更新我的卡路里标签。希望这解释得足够好!