gpt4 book ai didi

iOS实现导航类(class)不保存

转载 作者:行者123 更新时间:2023-11-28 08:26:51 25 4
gpt4 key购买 nike

我正在学习 Apple 关于处理 Xcode 的类(class)。我正在尝试通过单击 Storyboard上的保存按钮将新的“膳食”实例保存到我的表格 View 中。

在我的 mealViewcontroller 中,我有准备功能:

func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
if saveButton === sender {
let name = nameTextField.text ?? ""
let rating = ratingControl.rating
let image = mealImageView.image
meal = Meal(name: name, rating: rating, image: image)
}
}

在我的 MealTableViewController 中:

@IBAction func unwindToMealList(sender: UIStoryboardSegue){
if let sourceViewController = sender.source as? MealViewController, let meal = sourceViewController.meal {
let newIndexPath = NSIndexPath(row: meals.count, section: 0)
meals.append(meal)
tableView.insertRows(at: [newIndexPath as IndexPath], with: UITableViewRowAnimation.bottom)
}
}

我已将 MealTableViewController 上的保存按钮与退出项链接起来,并选择了 Action 序列“unwindToMealListWithSender”,它与我的函数“unwindToMealList”的名称不对应

这就是为什么当我添加一个项目并单击保存按钮时,没有任何内容添加到我的 MealView 中的原因吗?

我试过断点,但找不到问题所在。

有什么想法吗?

最佳答案

已解决:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if sender as? UIBarButtonItem === saveButton {
let name = nameTextField.text ?? ""
let rating = ratingControl.rating
let image = mealImageView.image
meal = Meal(name: name, rating: rating, image: image)
}
}

关于iOS实现导航类(class)不保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39753159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com