Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2009, 11:51 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 20
Unhappy Confused with a basic idea

Hi,
I am confused with a basic idea.

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 ?
cation007 is offline   Reply With Quote
Old 07-21-2009, 12:48 AM   #2 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

Your question is clear enough.

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
FlyingDiver is offline   Reply With Quote
Old 07-21-2009, 02:40 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 20
Default

Quote:
Originally Posted by FlyingDiver View Post
Your question is clear enough.

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.

appDelegate.m:
dataModel *dataObject = [[dataModel alloc] init];

Now, how will rootViewController access that object ?

(or)

what should be the code within rootViewController.m to access it ?

am I missing any basics about delegates ?
cation007 is offline   Reply With Quote
Old 07-21-2009, 09:48 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 791
Default

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...
nobre84 is offline   Reply With Quote
Old 07-21-2009, 09:52 AM   #5 (permalink)
Former NeXTStep Developer
 
Join Date: Mar 2009
Posts: 997
Default

in your view controller:

Code:
dataModel *theData = [[[UIApplication sharedApplication] delegate] dataObject];
Just make sure dataObject has a getter method or you synthesize properties for it.

joe

PS - the convention is to have class names start with uppercase (DataModel, not dataModel).
FlyingDiver is offline   Reply With Quote
Old 07-21-2009, 02:10 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 20
Smile

Hi, problem fixed

By mistake, I was removing all objects in the dealloc method in one of the subviews.

That fixed the problem.

Thanks a lot

Last edited by cation007; 07-21-2009 at 02:45 PM. Reason: Problem solved
cation007 is offline   Reply With Quote
Reply

Bookmarks

Tags
database, navigation controller, release, rootviewcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 248
18 members and 230 guests
ADY, Alsahir, beleg_1998, Dani77, e2applets, iDifferent, iph_s, JamesCahall, JasonR, mer10, Monstertaco, prchn4christ, Promo Dispenser, Robiwan, Rudy, smithdale87, spiderguy84, timle8n1
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,756
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:17 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0