gpt4 book ai didi

ios - 无法检查函数的引用相等性;这里的操作数类型为 'UIBarButtonItem' 和 '(UIBarButtonItem) -> ()'

转载 作者:行者123 更新时间:2023-11-28 15:40:16 26 4
gpt4 key购买 nike

我正在尝试 this Apple tutorial但我发现了一个错误。有人可以帮助我吗?

Disable Saving When the User Doesn't Enter an Item Name

What happens if a user tries to save a meal with no name? Because the meal property on MealViewController is an optional and you set your initializer up to fail if there’s no name, the Meal object doesn’t get created and added to the meal list—which is what you expect to happen. But you can take this a step further and keep users from accidentally trying to add meals without a name by disabling the Save button while they’re typing a meal name, and checking that they’ve specified a valid name before letting them dismiss the keyboard.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)

// Configure the destination view controller only when the save button is pressed.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
if #available(iOS 10.0, *) {
os_log("The save button was not pressed, cancelling", log: OSLog.default, type: .debug)
} else {
// Fallback on earlier versions.
}
return
}

let name = nameTextField.text ?? ""
let photo = photoImageView.image
let rating = ratingControl.rating

// Set the meal to be passed to MealTableViewController after the unwind segue.
meal = Meal(name: name, photo: photo, rating: rating)
}

最佳答案

saveButton 属性声明可能有问题。它应该输入为 UIBarButtonItem(而不是 (UIBarButtonItem) -> Void 如您的错误所示)。

为了安全起见,请尝试重复 Apple 教程中的将“保存”按钮连接到 MealViewController 代码步骤。

关于ios - 无法检查函数的引用相等性;这里的操作数类型为 'UIBarButtonItem' 和 '(UIBarButtonItem) -> ()',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43779579/

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