Bespoke App development for the Web and Devices

Referencing an iPhone App’s UIApplicationDelegate from a nested view


01.29.10 Posted in iPhone, objective-c by admin

It is useful to know that you can reference the top level of your application from anywhere since it is a Singleton.  This enables access to the application delegate as follows:

[[UIApplication sharedApplication] delegate];

This can be useful if you want declare your model at the top level of your app and need to reference it from other places.  In this case you would need to cast the delegate reference:

StemStopwatchAppDelegate* ref =
(StemStopwatchAppDelegate*) [[UIApplication sharedApplication] delegate];

I have also found it necessary to reference UIApplicationDelegate in a view with a UITabBarController when I wanted to use a UIActionSheet (a bit like a popup dialog).  This ensured that the actionsheet had focus and not the tabbar underneath when it was invoked:

[actionSheet showInView:ref.window];

Post to Twitter



Leave a Reply

You must be logged in to post a comment.

Twitter Updates
Mobile site
QR Code - scan to visit our mobile site