个InterfaceController

个InterfaceController

我使用reloadRootPageControllers加载4个InterfaceControllers,需要向每个InterfaceControllers传递一个上下文,但是使用下面的代码,只有数组中的第一个InterfaceController接收上下文。我怎么能把它传给四个人?

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


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

最佳答案

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

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

关于ios - 将上下文传递给多个InterfaceControllers?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49946510/

10-13 09:26