티스토리 뷰


// ProductDetailView.swift
Button {
isModalPresented.toggle()
} label: {
Text("구매하기")
}
.buttonStyle(ProductButtonStyle(height: 56, isMaxWidth: true))
.sheet(isPresented: $isModalPresented) {
ProductOrderView(viewModel: viewModel)
.presentationDetents([.height(80)])
}
이렇게 구매하기 버튼을 누르고 결제하기, 장바구니 modal을 띄우면 현재 뷰가 갑자기 자기 혼자 사라진다.. dismiss를 누른 것 처럼…
근데 알고보니 문제는 관련 뷰들의 코드에 없었다!
해결 방법
// MainTabView.swift
NavigationStack {
ZStack {
Color.clear
.ignoresSafeArea()
TabView(selection: $selectedIndex) {
HomeView(viewModel: homeViewModel)
.onAppear {
selectedIndex = 0
}
.tabItem {
Image(systemName: "house")
Text("홈")
}
.tag(0)
CategoryView()
.onAppear {
selectedIndex = 1
}
.tabItem {
Image(systemName: "list.dash")
Text("카테고리")
}
.tag(1)
MyPageView()
.onAppear {
selectedIndex = 2
}
.tabItem {
Image(systemName: "person.fill")
Text("마이페이지")
}
.tag(2)
}
.accentColor(.black)
}
}
그저 NavigationView를 NavigationStack으로 바꿔주면 된다! iOS16부터는 NavigationView가 deprecated되고 NavigationStack을 쓴다고 한다. 하지만 이걸 바꾼다고 왜 해결되는지는 잘 모르겠다 ㅎ 이것도 찾아봐야겠다.
그리고 생각해보니 NavigationStack은 앱 클론하면서 봤던거임.. (〃⌒▽⌒〃)ゝ
'iOS > SwiftUI' 카테고리의 다른 글
[SwiftUI] 기본 폰트 크기 (0) | 2024.10.04 |
---|---|
[SwiftUI] TabView에 그림자 적용하기 (0) | 2024.10.04 |
[SwiftUI] 스플래시 스크린 띄우기 (0) | 2024.03.19 |
[SwiftUI] 배너와 자동스크롤 구현하기 (0) | 2024.03.06 |
[SwiftUI] ForEach Cell 삭제 구현하기 (마지막 Cell이 삭제되는 이슈 피하기) (0) | 2024.03.05 |