I have a table view which has custom cells. My table view cell get populated through the values inserted in an SQLite database.
The database values are shown in my table view cells, but the problem is, when I navigate from my table view to the previous view, and back to the tableview through the navigation bar, the table view becomes empty. What might be the problem?
Edited to suggest a more likely solution based on comments to this answer
Assuming you’re adding the login view as a modal viewController, you need to refresh the table after each additional login. In your
viewWillAppearmethod reload your tableView:Or, if your table takes a while to reload, you can send a notification to the viewController to reload the tableView from the login view before you dismiss it.
Currently-not-visible views can be unloaded at-will by the OS if memory gets tight. A common iOS development mistake is to assume that the code in a viewController’sviewDidLoadandviewDidUnloadmethods will only be called when the view is first loaded and later unloaded. Check to make sure that yourviewDidLoadmethod isn’t making any assumptions about the availability of data and that yourviewDidUnloadmethod isn’t accidentally deleting data that the newly re-calledviewDidLoadwill need.Similarly, ensure that your
viewWillAppearmethod isn’t being thwarted by something in yourviewDidUnloadmethod.Lastly, and in the same vein, understand that if your view gets dumped by the OS for memory reasons, it will sometimes call your
viewDidUnloadmethod as it clears it out, but sometimes seems to not call it, perhaps because the memory used by the view was so great that a failure to clear things out in itsdidReceiveMemoryWarningmethod made it decide to just dump the view immediately and completely, without really allowing it to clean itself up.