PDA

View Full Version : General App Organization Question




jjgraz
Apr 22, 2009, 02:46 PM
I have an application which upon DidFinishLaunching in AppDelegate makes a call to a webservice/database to fetch data for parsing and puts it into a tableView. Now I have added a second TableView on a second TabBar item which does the same, only it pulls a different set of data from the database and inserts it into the same variable. In other words: History TableView & Active Inbox TableView. My Question is: What is the best method for making two calls to my server when both sets of data are using the same variables for parsing and entry to TableViews. The following are my ideas to implement this. Just not sure which is cleanest or if one method is highly recommended. Any thoughts are appreciated. Thank you.

1) In AppDidFinishLaunching send two requests one after another and have the seperate requests brought back into different variables so they may be dealt with accordingly.

2) In AppDidFinishLaunching send a single reguest for say Inbox so it can be updated, then create a seperate method for the second request in AppDelegate which is only called if the user selects the tab for history.(history would only update once selected may slow the app down for user interaction, but would also display the most current information....for instance if a user selected the inbox and sent an item to history, that item would be there upon selecting history Tab)

3) A collaboration of the two.....Send two requests at AppDidFinishLaunching, and also have two seperate methods in appDidFinishLaunching which are called when a user selects either history or inbox allowing the latest data always in the tableviews.

4) One Request that gets both sets of data in the AppDidFinishLaunching and puts the lot into a variable and a set of if/else statements in the perspective viewControllers that would search the returned data for a tag or seperating element to display only a portion of all returned data in correct TableViews.

Is there a preferred standard for this?
I appreciate it.



fishkorp
Apr 22, 2009, 03:16 PM
Is there a particular reason you're making the request in the app delegate instead of in each tab bar item's view controller?

jjgraz
Apr 22, 2009, 03:36 PM
None other then I have the parser set up to retrieve the returndata from the appDelegate. I also thought it was a good practice to have AppDidFinishLaunching send the request so data is there and ready when the user selects a tab.....You think i should have a link to the parser in each ViewController instead?

fishkorp
Apr 22, 2009, 09:39 PM
I'm not sure if there's a best practice for this, but I found it easier to make the request/load the data on each view controller. The app loaded quicker initially and the other data was only fetched if it needed to be fetched. This isn't what my app does, I'm just using it as an example. Say there are 3 tabs, one to get news from CNN, one to get the forecast for your saved cities, and one to get the tour dates of your favorite band. If someone opens up the app just to check the news headlines, there's no point in fetching all the other data. I guess it really depends on the app. TwitterFon will fetch/load everything at once, which is convenient for a Twitter app and makes sense. An app like I described above more than likely wouldn't need all the data fetched at once.

Guess it's a matter of what works best for your application?

jjgraz
Apr 23, 2009, 11:17 PM
So I have come to terms with sending requests from the individual viewControllers.......However, what is the method you use, so everytime the tabBar Item is selected it sends out a request thus updating the tableviews each time......

ViewDidLoad is not correct, as it only loads the data once. Is there a quick method to refresh viewdidload everytime or another way?