Navigating between multiple views with TabView
Navigation views are ideal for displaying hierarchical data because they allow users to drill down into the data. Navigation views, however, don't work well with unrelated data. We use SwiftUI's TabView
struct for that purpose.
Getting ready
Create a new SwiftUI iOS app named UsingTabViews
.
How to do it
We will create an app with two TabView
structs where one displays the top games of 2020, while the other displays some world currencies. The steps are as follows:
- Create a SwiftUI view called
HomeView
:a. Press ⌘ + N.
b. Select SwiftUI View.
c. Click Next.
d. Click on the Save as field and enter the text
HomeView
. - Before the
struct HomeView
line, create a string array containing the various games:let games = ["Doom", "Final F","Cyberpunk", "avengers", "animal trivia", "sudoku", "snakes and ladders", "Power &...