问题
Is there a way to use TabView using SwiftUI on WatchOS?
I've seen most of the WWDC talks and they don't mention it for WatchOS. Moreover, in the apple documentation it is not enumerated under SDK's.
Whenever I try to add it to a WatchOS project I get the following error:
'TabView' is unavailable in watchOS
Or is there a good way to replicate the desired TabView ?
I want something similar to this: Two different pages that are changed simply by swiping horizontally.
回答1:
If you want a page based navigation (swipe left/right between view controllers) in your app you simply add another WKHostingController to your project's storyboard. Connect the two hosting controllers by creating a segue between them. The segue is what determines how you navigate between controllers.
This page has a good guide on how to do it: https://www.techotopia.com/index.php/A_WatchKit_Page-based_Navigation_Tutorial
Just keep in mind that you want to add another hosting controller to the storyboard, not anything else.
I have not found a way to do this programmatically in SwiftUI, this seems like the only way to do it for now.
来源:https://stackoverflow.com/questions/58036807/cannot-use-tabview-on-swiftui-watchos