I have a database and I want to load it and use it in my application.
Application uses navigation controller.
The problem is, when and where should I load the values from the database ?
in application delegate or rootviewcontroller ?
If I do it in rootviewcontroller, everytime I move between different tableviews, the variables get released and the database is loaded again and again.
If I do it in appDelegate, I dont know how to pass the values to the rootviewcontroller.
I want to read the database only once for this whole application.
How can I solve this problem?
How do ppl normally work with databases (i.e, when and where do they read from databases) ?
Thanks for replying.
p.s. Is my question not clear ?
The usual method is to have a class just to manage the database. You create an instance of the class in your AppDelegate, and initialize it from the database. Then, any view or controller or whatever that needs access to the data gets the pointer to the Data class from the AppDelegate, and messages that Data class to get the info needed.
That way the internals of the data storage are encapsulated in that one data management class.
The usual method is to have a class just to manage the database. You create an instance of the class in your AppDelegate, and initialize it from the database. Then, any view or controller or whatever that needs access to the data gets the pointer to the Data class from the AppDelegate, and messages that Data class to get the info needed.
That way the internals of the data storage are encapsulated in that one data management class.
joe
Hi,
Thanks for replying.
I got what you meant. But I still din't understand how it works.
Say for Eg:
I have a model called dataModel. and I create an object and initialize within the appDelegate.
Anywhere in your program you can access the delegate with the following:
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
Then you can access your database class from there...