I have a class that communicates with a server (let’s call it ‘Downloader’). Sometimes, the server may reject the connection due to a bad login. Instances of this class are used thru-out my program by many different objects, and when the login is rejected Downloader needs to tell the RootViewController to display a login interface. Many of the classes that utilize an instance of Downloader don’t have a reference to the RootViewController, so I am sending the message through my application delegate (which has a reference to RootViewController), like so:
[[[UIApplication sharedApplication] delegate] loginFailed];
The application delegate then tells the rootViewController to display the login interface. My question is this: is this the best or ‘proper’ way to do this? It works, but I am trying to stick to coding conventions. Is there a better way?
Your method is pretty common and correct. I find if you are doing this often you might want to add a helper method like this:
Then anywhere in your app you can use:
Just replace all the names above with your class names.