views:

45

answers:

1

Hey guys,

I found some useful information on the web but I still can't manage to do it by myself ;)

Ok, let me put my problem in context for you :

I have a first class (myViewController) whose declaration is below :

// i just give you relevant information
RssParser *rssParser;
UIActivityIndicator *activityIndicator;

In my viewDidLoad method (myViewController) I have :

//once again, I summarize it for you
[activityIndicator startAnimating];
[rssParser parse];

Now, suppose you are in the parserDidEndDocument method (which is in RssParser class), how am I suppose to stop the animation of the activityIndicator ? How can I get access to my instance of activity Indicator from the RssParser class ?

Hope I made myself clear ;)

Thanks guys!

Gauthier

+1  A: 

A common way to do this is to use a delegate. Check the RssParser class for the use of a delegate or implement one yourself. Set the delegate of rssParser to self in MyViewController. Now you can implement the method that is called after the document is parse with MyViewController. If you create an ivar for activityIndicator then you can easily access activityIndicator again.

Diederik Hoogenboom
Sorry, i should have made myselfclearer ... In fact RssParser is a subclass of NSXMLParser and the reason why i suclassed it is because i want my code to beclear ! So the delegate is actually RssParser and i want it to communicate with my original class (myViewController). Cheers mate ;)
gotye
Why not let myViewController be the delegate instead of RssParser? You can always implement a second delegate of course.
Diederik Hoogenboom
Because if myViewController is the delegate, it means I need to implement all delegate methods in myViewController. And it will be a big mess ;)
gotye
Just add an idea, I don't know if this is the best solution but if I put something like that in my delegate (RssParser) :appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];I think I could get access to myViewController from this point ... what's your thoughts ?
gotye
Might work in this particular case but is not really reusable. Why not create an alternateDelegate property in RssData and then just set the delegate in myViewController by rssParser.alternateDelegate = self
Diederik Hoogenboom
Sorry, didn't really understand your last post, could you start it again ?
gotye