iPhone - Write in app delegate - iphone

i have to write some code that initialize my data app. This must be made before the app the app is loaded. In my opinion the best way is to write this code in app delegate. Am i right?
p.s. : the code download some xml from the net and parse a lot of data and put in core data.

Depending on the exact context you can also implement a + (void)initialize method in your class.

YES friend if you write on applicationDidFinishLaunching method in appDelegate ..then webservice get called before the app launch and you have all that data when you start your application . for that you need to set connection by AsiHTTP connection DElegate and parse using NSXmlParserDelegate..

Yes , its right to call xml parsing in appdelegate so that you had data , before your app first view loads.

Related

Problems getting an xml feed parsed and loaded into a tableview using delegates

Very new to programming for iOS and Cocoa so please take it easy on me as I try to wrap my brain around the following. I'm trying to display a tableview populated from an XML feed as the opening screen of my app. I've tried to consume the XML from inside my AppDelegate using the ApplicationDidFinishLaunching method (and then making my AppDelegate a delegate for the XML parser which I access using a NSUrlConnection and its delegate methods) but I can't figure out how to take the parsed XML file and pass it to a tableviewcontroller which can then use it as the datasource for a tableview. When I do try, I always get a blank tableview.
I've written the code a few times and nothing seems to work.. I'll post what I have here to show what I've got so far but I'm afraid its mostly vanilla AppDelegate with a few parser methods thrown in.. any pointers in the right direction would be super appreciated.
Thank you in advance!
Hmm, probably a bad idea to do the network call in the AppDelegate. Try to put all that code at the view controller level. Here's a brief structure of what I do (Since it's very similar)
View Controller listens to button events
Use ASIHTTPRequest to talk to your web service. Handles network really well, you can skip the NSURLConnection stuff.
Try to load your data source (an array?) with static values and see if they come up on the table view.
Parse the response from ASIHTTPRequest using NSXMLParser, and load the data you want into the static array you were using. More here.
Call [tableView reloadData] once you're done and the changes will reflect.
Did you specify a UITableViewDataSource for your table view and implement the two required methods?
tableView:cellForRowAtIndexPath:
and
tableView:numberOfRowsInSection:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html
When I get blank tables, this is what it is; I've forgotten to specify the data source

Declaring MutableArray of Custome class in to AppDelegate of iPhone application

I am working on iPhone application in which i have more than 20 class and i am declaring that classes NSMutableArray into my application's app Delegate file, and accessing them from my different views.
All NSMutableArray are filled by XMLParsar requesting from server.
My application is getting slow in process, is it because i have declare in app delegate file?
or is that proper way to implement?(declaring all objects into app delegate file.)
Thanks.
Nope, you should try to keep your application delegate as simple as possible. There are other ways how to handle shared data - singleton for example. Here's an example: http://www.johnwordsworth.com/2010/04/iphone-code-snippet-the-singleton-pattern/ There also other methods too, depends on your task and application.

how to parsing the xml and showing the table

Hi friends i tried to parse the xml and show in table view .
but without use of appDelegate object how can we .
i have seen in many site that was started from application beginning .
but i want to know if i need to parse and show in different view controller which is not root
view controller and also should not use the application delegate?
please any genius
So it sounds like you have a data model saved as XML somewhere, and when your application loads, you want to parse it and keep the model in memory.
In my experience, the application delegate is actually the place to keep stuff like this. Since it's something that both the application delegate, and the random UIViewController need to know about, the app delegate is a good place to keep it.
Once you've loaded your model using the NSXMLParser or your preferred loader, you can (in your UIViewController) use something like:
MyModel *model = ((MyAppDelegate *)[[UIApplication sharedApplication] delegate]).myModel;

Not able to call application delegate method

I am developing app with finding audio frequency by using FFT. In my app, I am not able to call application delegate method in app delegate class as given in below, but I could able to call other custom methods in app delegate class. What mistake I have done?
Please help me!
(void)applicationDidFinishLaunching:(UIApplication *)application
It looks like your project files have got a bit mixed up. To be honest, it's probably easier to start with a new application template as a base and then add your changes into it. If that is not possible, have a look at the following
In your {project_name}.plist file under the Resources folder you should see a setting
Main nib file base name
This will tell you which nib file is loaded at the start (normally MainWindow). Open this file and have a look for 'Files Owner' 'UIApplication'. Right click on this and there should be a link to the delegate. If it isn't there, then that's your problem
Check to make sure your application delegate inherits from NSObject and NOT NSApplication as NSApplication is a singleton. Otherwise your application object will be its own delegate.
You should now be using application:didFinishLaunchingWithOptions:

save a view with NSUserDefaults {iPhone SDK}

i try to use NSUserDefault or something like this , to save a specific view after quit from application and when user lunch application again load from that view ... but i dont know how!
I would suggest you have a look at the NSCoder class and its related components. The API is specifically built for arching and dearchiving Objective-C class instances.