diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift index 59dae6f69..de935fd04 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceConfiguration/ServiceConfigurationCells.swift @@ -73,22 +73,27 @@ struct ServiceConfigurationPickerCell) { self.titleKey = titleKey _value = .init(key) - _isOn = State(initialValue: value == "1") + viewModel.isOn = value == "1" } var body: some View { - Toggle(titleKey, isOn: $isOn) + Toggle(titleKey, isOn: $viewModel.isOn) .padding(10.0) - .onChange(of: isOn) { newValue in + .onChange(of: viewModel.isOn) { newValue in value = newValue ? "1" : "0" } } diff --git a/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift b/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift index 56239930a..83a5f6398 100644 --- a/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift +++ b/Easydict/NewApp/View/SettingView/Tabs/ServiceTab.swift @@ -64,9 +64,6 @@ struct ServiceTab: View { } } } - .onDisappear { - viewModel.selectedService = nil - } .layoutPriority(1) } .environmentObject(viewModel)