How can I pass data loaded when my application finished launching thru my UITabBar to a UITableView?

DeeNove750

I am a new iOS programmer and I am trying to make an application that involves the following flow:

-> UITabBar -> UINavController -> UITableViewController.

Initially the program was working when I have the following flow:

-> UINavController -> UITableViewController

But when I added the UITabBar (with the Embed In method)the I had two issues:

1) Casting the initial view from UITableView to UITabBarView 2) The data which have been restored from Archives of the phone are not loading in the TableView.

I managed to fix the casting issue with the UIStoryboard IDs, but I am not sure if this way I created the second problem of not passing data to the UITableView correctly.

The Casting problem has taking place at the appDelegate code. Here is the original code I had before incorporating the UITabBarView:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let navController = window!.rootViewController as! UINavigationController

let SLBprojectController = navController.topViewController as! GR8TableView

SLBprojectController.SLBprojectDB = thisSLBprojectDB

return true
}

The problem with the above code was that it told me that it could not cast a TableViewController (GR8TableView) into a UITabBarView. I have managed to fix this by searching in the StackOverflow forums by making the following:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)

let tabBarIntial : UITabBarController = mainStoryboardIpad.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController

let navigationController:UINavigationController = mainStoryboardIpad.instantiateViewController(withIdentifier: "navController") as! UINavigationController

let navigationController1:UIViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "ViewController1")

let SLBprojectController = navigationController.topViewController as! GR8TableView

SLBprojectController.SLBprojectDB = thisSLBprojectDB

tabBarIntial.viewControllers = [navigationController, navigationController1]

tabBarIntial.selectedIndex = 0

return true

}

But after I fixed the "casting" issue then I am getting problems loading the data in the TableView. Not sure if this problem is related to the way I fixed the casting issue.

Any assistance would be much much appreciated!

Phillip Mills

The simplest answer would be to go back to logic similar to what worked for you, but with a slightly more complex relationship. For example, I created an app with a tab bar controller, a navigation controller in the first tab, and a FirstViewController embedded in the navigation controller.

Since I don't have a database, I gave the FirstViewController a single instance variable called running.

The following code finds the controller and sets the variable:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    if let tabController = window!.rootViewController as? UITabBarController {
        if let navController = tabController.viewControllers![0] as? UINavigationController {
            if let firstController = navController.topViewController as? FirstViewController {
                firstController.running = true
            } else {
                print("Unexpected controller in navigation hierarchy: \(String(describing: navController.topViewController))")
            }
        } else {
            print("Unexpected contained controller: \(String(describing: tabController.viewControllers![0]))")
        }
    } else {
        print("Unexpected root controller: \(String(describing: window!.rootViewController))")
    }
    return true
}

Note that I'm not creating any new controllers. That's all done by default storyboard loading.

I believe you should be able to adapt this to your own variable and class names.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I pass data to my app when launching from a link?

How can I load my data before the component is loaded?

How can I execute my code after data load is finished on my react project

How do I prevent the Photos application from launching when my iPhone gets plugged in?

How can I add a logout button to my UITabBar

How can I pass an id of "0" into my application URL? (CodeIgniter)

How can I store the spark's log output when launching in my local machine through intellij?

How can I tell when all of the asynchronous calls on my page have finished (Parse Cloud functions)?

How can I pass my method an activity when it is not in an activity?

How can I pass data to my child component?

How can I pass data from a service into my controller?

How can I observe LiveData and then pass this data to my adapter?

How can i pass Data into my SQLite-Database

How can I track down why my activity gets finished?

How do I check when my ListView has finished redrawing?

How can I make my application logout when the browser is closed?

How can i start my application when network connection is available?

How can I architecture my application to backtest data in Rails?

How can I access the text of the SMS sent thru Twilio to my Spring Boot Controller?

How can I pass my Todo component Data into my Todolist component using React hooks?

How can I pass my LinQ generated data from a controller to my secondary View

How can i pass my variable values from console application to windows form application

In Picasso library how can I now when my image gets loaded which event listener gets triggered?

I can't get my UITableView to reload data in swift

How can I make spring.xml's xsi:schemaLocation work when my app is offline (finished product is an offline artifact)

How can I stop my UITableView from crashing when the array is empty?

How can I use application-scoped resources when my application builds as 'Page' and not 'Application Definition'?

How can I pass a variable from my post to my get?

How can I pass my search keyword to my Controller?