将上下文传递给多个InterfaceControllers?

时间:2018-04-20 16:59:19

标签: ios swift watchkit apple-watch

我使用reloadRootPageControllers加载4个InterfaceControllers,我需要将一个上下文传递给每个,但是使用下面的代码,只有数组中的第一个InterfaceController接收上下文。我如何将它传递给所有4个?

let contextDictionary = ["workoutConfiguration" : workoutConfiguration, "ActivityType": selectedActivityType, "workoutManager" : workoutManager] as [String : Any]


        WKInterfaceController.reloadRootPageControllers(withNames: ["WorkoutControlsInterfaceController", "MainDisplayInterfaceController", "SpeedInterfaceController", "CaloriesAndDistanceInterfaceController"],
                                                        contexts: [contextDictionary],
                                                        orientation: .horizontal,
                                                        pageIndex: 1)

1 个答案:

答案 0 :(得分:1)

您需要使用与contextDictionary数组withNames相同的数组。

WKInterfaceController.reloadRootPageControllers(withNames: ["WorkoutControlsInterfaceController", "MainDisplayInterfaceController", "SpeedInterfaceController", "CaloriesAndDistanceInterfaceController"],
                                                    contexts: [contextDictionary, contextDictionary, contextDictionary, contextDictionary],
                                                    orientation: .horizontal,
                                                    pageIndex: 1)