0

The situation I am running in is that, I have a login Button which is having NSURLConnection method in the main view controller and when button is pressed it will be active and and XML file will be downloaded. Now to parse that XML file the method which is parsing is in application delegate file.

Now I want to know that how can I call that function from within the login button. And also that from that parsed file I have to check a value that if it is more than 1 or less than one. So that the action would be taken that to which view it will be transitioned.

any help will be appreciated.

  • 1
    You should reconsider parsing the XML somewhere else but in the AppDelegate. It is considered bad style to misuse the AppDelegate as the one and only singleton stuffed with functionality that has nothing to do with the UIApplication itself. – Till Dec 02 '11 at 13:11

2 Answers2

1

If the method to do your parsing lives in the application delegate, then getting a hook to it can be as easy as:

MyFineApplicationDelegate * appDelegate = 
    (MyFineApplicationDelegate *)[[UIApplication sharedApplication] delegate];

And then you can call [appDelegate parseMyXMLData: myXMLData];

Makes sense?

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • No, its not working. Actually here I also have to use one of the node of XML file for if/else block. –  Dec 02 '11 at 13:28
  • if it's not working, modify your original question to be somewhat more clear about ***how*** using the AppDelegate this way is not working. Also, @Till is right: you shouldn't be putting parsing code in the AppDelegate like this. – Michael Dautermann Dec 02 '11 at 13:32
  • Thanks! Yes @Michael I an considering Till's suggestion and I think I would have to change the code to get it work properly. Because in this way it is getting complicated and It would be full of bugs. Can you tell me about any tutorial In which It would be explained that how can we use the nsxmlparser right after the data saved and parse it and then use it in NSDictionary to get the desired node value to make decision. –  Dec 02 '11 at 13:40
  • The [answers to this related question](http://stackoverflow.com/questions/2964503/nsxmlparser-on-the-iphone-how-do-i-use-it-given-a-xml-file-newb-here) may help you out. – Michael Dautermann Dec 02 '11 at 13:49
0
Try This..
In .h
#import "Appdelegatefile.h"

Appdelegatefile * appDelegate;


IN .m 
{
 appDelegate =(Appdelegatefile *)[[UIApplication sharedApplication] delegate];
[appDelegate //here you can call method of delegate file ];

}
Kartik
  • 779
  • 7
  • 22