У меня есть навигационная иерархия, структурированная как следующее: < /p>
Root View -> View A -> View B -> View C -> View D
< /code>
RootView() .navigationDestination(
for: DashboardDestinations.self,
destination: { screen in
switch screen {
case .ScreenA:
ScreenA()
case .ScreenB:
ScreenB()
})
}
< /code>
class DashboardRouter: ObservableObject {
var path = NavigationPath()
static let shared: DashboardRouter = DashboardRouter()
func popToRoot() {
path = NavigationPath()
}
func popToView B() {
path = NavigationPath([DashboardDestinations.ViewA, DashboardDestinations.ViewB])
}
}
< /code>
In my DashboardRouter class, I manage navigation using a NavigationPath.
When I’m in View D and trigger a button to go back to View B by resetting the navigation path:
DashboardRouter.shared.popToViewB()
< /code>
and then navigate forward again to View C, I notice that View C’s state is preserved from the previous time it was shown, instead of being reset.
Why does the state of View C persist after popping back to View B and navigating forward again? How can I make sure View C resets its state when I navigate to it again?
Подробнее здесь: https://stackoverflow.com/questions/796 ... back-and-f
Swiftui NavigationStack - Почему View State сохраняется при навигации вперед и назад? ⇐ IOS
Программируем под IOS
1746119081
Anonymous
У меня есть навигационная иерархия, структурированная как следующее: < /p>
Root View -> View A -> View B -> View C -> View D
< /code>
RootView() .navigationDestination(
for: DashboardDestinations.self,
destination: { screen in
switch screen {
case .ScreenA:
ScreenA()
case .ScreenB:
ScreenB()
})
}
< /code>
class DashboardRouter: ObservableObject {
var path = NavigationPath()
static let shared: DashboardRouter = DashboardRouter()
func popToRoot() {
path = NavigationPath()
}
func popToView B() {
path = NavigationPath([DashboardDestinations.ViewA, DashboardDestinations.ViewB])
}
}
< /code>
In my DashboardRouter class, I manage navigation using a NavigationPath.
When I’m in View D and trigger a button to go back to View B by resetting the navigation path:
DashboardRouter.shared.popToViewB()
< /code>
and then navigate forward again to View C, I notice that View C’s state is preserved from the previous time it was shown, instead of being reset.
Why does the state of View C persist after popping back to View B and navigating forward again? How can I make sure View C resets its state when I navigate to it again?
Подробнее здесь: [url]https://stackoverflow.com/questions/79602206/swiftui-navigationstack-why-does-view-state-persist-when-navigating-back-and-f[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия