Recipes App | SwiftUI | Creating the pages

Hi!

I’ve got a problem.

I’ve currently started with coding of apps and after a few hours and days i finally have a working tabBar with options, icons and different pages the problem is, each of these tabs don’t display anything, when i click them except a white page(since there’s no code for it)

How do i make it possible for me to code content into these blank pages that’s gonna show recipes etc. (! The tabBar itself is already completely done) all i want now is to start coding so the tabicons lead me somewhere to like recipes, now i’m coming to a white page.

i also want each category to have a seperate file in the coding, like “recipes” have it’s coding in one file and “my account” has a completely seperate file in the coding (so if i accendently erase the “my account” coding the “recipes” coding isn’t affected at all cause it’s not in the same file.

// Thanks

Unless you clarify what you have done till now, it is hard to say something sure.

I didn't notice it was SwiftUI (the tags do not tell correctly). In SwiftUI, it is direct: when you create the TabView, you will have in the main view (with all the tabs), code such as:

         TabView {
            FirstTabView()
                .tabItem {
                    Label("1st", systemImage: "list.dash")
                }

            SecondTabView()
                .tabItem {
                    Label("2nd", systemImage: "square.and.pencil")
                }
         }

Note: In UIKit, the simplest way to do this:

  • In IB, you create ViewControllers for each destination page (one for each tab bar icon)
  • You add objects in this VC
  • You connect the tabBarController with a relationship segue (connect in the right order, the VC for the first tab first)
  • You create a class for each VC (let's say class FirstViewController: UIViewController { }
  • In IB, in Identity inspector, set the class of the VC(s): FirstViewController for the first VC
  • Now you can connect the IBOutlets, the IBActions of objects FirstViewController to the code.
Accepted Answer

You create the files in the project as I explained in the other thread.

The struct will be named FirstTabView and SecondTabView.

Those files content will look like this: FirstTabView.swift

import SwiftUI

struct FirstTabView: View {
    var body: some View {
        Text("Hello, FirstTabView!")
    }
}

struct FirstTabView_Previews: PreviewProvider {
    static var previews: some View {
        MySwiftUIView()
    }
}

and SecondTabView.swift

import SwiftUI

struct SecondTabView: View {
    var body: some View {
        Text("Hello, SecondTabView!")
    }
}

struct SecondTabView_Previews: PreviewProvider {
    static var previews: some View {
        MySwiftUIView()
    }
}

The connection to the tabBar is made by this code in the parent View (the one which will contain the tabbar)

         TabView {
            FirstTabView()
                .tabItem {
                    Label("1st", systemImage: "list.dash")
                }

Wait omg, it works, it works, OMG THANK YOU. SO SO SO MUCH. THANK YOU

You've experienced the incredible pleasure of app development when it suddenly works.

have a good continuation (don't forget to close your thread).

Recipes App | SwiftUI | Creating the pages
 
 
Q