我已经寻找解决此问题的方法,甚至尝试遵循一些教程来尝试解决此问题,但由于某种原因,我最终遇到了同样的问题。我正在尝试将自定义对象传递给不同的视图控制器,但每次尝试时都会收到错误消息“'UIViewController' 类型的值没有成员'newExerciseDelegate'”
我的代表:
protocol exerciseDelegate {
func savedExercise(newExercise: Exercise)
}
我的发送 VC 使用以下代码:
var newExerciseDelegate: exerciseDelegate!
.
.
.
@IBAction func saveExerciseWasPressed(_ sender: UIButton) {
if (checkFields() == true){
newExercise = Exercise(name: exerciseNameField.text!, weight: Int32(weightField.text!)!, reps: Int32(numberOfRepsField.text!)!, sets: Int32(numberOfSetsField.text!)!, muscleGroupFocus: .cardio)
newExerciseDelegate.savedExercise(newExercise: newExercise)
dismiss(animated: false, completion: nil)
}
}
我的接收 VC 使用以下代码:
@IBAction func addExerciseBtnWasPressed(_ sender: Any) {
guard let newExerciseVC = storyboard?.instantiateViewController(withIdentifier: "NewExerciseVC") else { return }
newExerciseVC.newExerciseDelegate = self // error present on this line
presentDetail(newExerciseVC)
}
我确定这是一个愚蠢的错误,但我没有看到它。任何帮助表示赞赏,谢谢。