Cannot use TabView on SwiftUI, WatchOS

浪子不回头ぞ 提交于 2019-12-20 05:21:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!