我有一个 ViewController (planExercise),它存储一组练习对象,
class planExercise: UIViewController {
var exerciseList = [
Exercise(type: "Cardiovascular", name: "Walking", imageName: "walking", calories: 150, time: 30, isComplete: false),
Exercise(type:"Strength",name:"Chair Squats",imageName:"cycling", calories: 200, time: 15, isComplete: false),
Exercise(type: "Flexibility", name: "Seated Toe Touch", imageName: "squats", calories: 100, time: 15, isComplete: false)
]
我有另一个 ViewController (TableViewDetail),当我单击按钮时,它基本上会添加到exerciseList 数组中,这就是我到目前为止所拥有的:
@IBAction func didTapAdd(){
planExercise().exerciseList.append(selectedExercise)
}
我尝试在TableViewDetail ViewController中调用planExercise ViewController,然后访问其中的exerciseList数组并将selectedExercise附加到其中,但是当我运行应用程序时,planExercise ViewController中的exerciseList数组没有任何反应,并且它没有更新.
因为
planExercise()
这里
planExercise().exerciseList.append(selectedExercise)
是除显示实例之外的新实例,您需要使用委托来传递要更改其数组的实际实例