Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use TabView on SwiftUI, WatchOS

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: enter image description here Two different pages that are changed simply by swiping horizontally.

like image 289
39fredy Avatar asked Sep 21 '19 02:09

39fredy


Video Answer


2 Answers

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.

like image 133
heinz_dieter Avatar answered Oct 22 '22 19:10

heinz_dieter


It's now available starting with watchOS 7: https://developer.apple.com/documentation/swiftui/tabview.

like image 5
Austin Conlon Avatar answered Oct 22 '22 19:10

Austin Conlon