Anish Rana Anish Rana - 8 months ago 34
Swift Question

Passing data between TableVIewControllers using Arrays.. Using Swift and Firebase

[Here's my Database Structure..

I have added two table view controllers in Storyboard. Lets name them TableView1 and TableView2.

TableView1 displays no. of items in categories node.. i.e Bikes, Trucks etc..

What i am trying to achieve is when the user clicks on particular cell..

TableView2 displays all the items in the respective node selected from the cell in TableView1..

For eg. if user clicked on the cell which displays bike.. TableView2 should load all the times from the bike node...


You can use something like the code below. Your value will make it over to the other view controller however when I tested my equivalent of this code my variable on the second view would not initialize until after veiwDidLoad. So just be aware of that. That's as far as I am able to help here.

EDIT: I realized that you wanted more. So you have to trigger your query some how. I've tried doing it by using the didSelectRowAtIndexPath method to do this. I don't know which of their query methods you want to use, so I am not going to guess. As I said before you will need to find someway to access your variable after the segue has taken place. Something I have had issues with. This should put you in the right direction though.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    var DestViewController: thenameofyourviewcontrollergoeshere = segue.destinationViewController as! thenameofyourviewcontrollergoeshere

     DestViewController.yourvaronotherview = thevarstoringthevalueyouwantonthisviewcontroller