Hi, I have a view controller that includes a method to create a dictionary. I can access the items in the dictionary inside the method. But I cannot access the items outside the method even within the same view controller. I want to access the items in the dictionary to create cells in a tableview cell in another view controller.
I am missing something fundamental about how to do this and I have not been able to figure it out with numerous google searches.
Hi Mike, I had declared the dictionary in a separate class. However, it wasn’t a ViewController class. I just made it a subclass of UIViewController but I still can’t access it outside the method.
Ok, I am now able to read the dictionary values. They don’t show top the first time the button is tapped bu they show uptake second and subsequent times. Not sure why that is.
However, when I moved the generation of the data to the other view controller alongside displaying the data and then called the function from viewdidload I still get a blank tableviewcell the first time.
I then tried the override function viewwillappear with no difference.
I have tried switching code around and what I have determined is that the sequence seems to go to the override func for the collection view before it populates the array. The array is called up as a get function in the override func viewdidload.
When I step through the code it calls the get function, appears to ge to the fire cloud database and retrieve the information but as part of that step it seems to go the override func for the collection view. Since the array hasn’t been populated it displays a blank view.
But when I step through the code a second time the array gets populated and the collection view gets displayed.
I should also note that sometimes I have to step through the code more than a second time to display the data.
I think the best hack would be to put another getEngineReport() at your viewDidLoad so it loads the the data first, then calls viewWillAppear to load again
what i see is that the main issue is in the
numberOfItemsInSection
because the count is based on data, which you do not have on your first run
Ok, that might explain it, but I already tried putting another getEngineReport() in viewDidLoad and that didn’t work. Also, sometimes it takes two or three refreshes before I see the data.
How should I have coded this? Is there a better way to create the cell?
or maybe just simply open it with a blank table, put a load data button, press it (maybe put on a loading animation for a few secs, then populate the tableview
Thanks, I was thinking of a loading screen as well. But what I find strange is it seems to run through the for loop without actually getting the data. I put a print database command just inside the four loop and it prints an empty database 28 times and then calls up the collection view which obviously shows an empty cell.
What would cause it to loop through the database 28 times and not actually create the data?