Craig Moore
Craig Moore

Reputation: 1091

Access current view from AppDelegate

I am attempting to access the current view from my App Delegate. Inside my app delegate there is a timed event that accesses a remote server every 30 seconds. If it finds a need to update the current data I need it to show a progress display "Please Wait" modal popup over the current view.

I want to use the DejalActivityView to display the "Please Wait" window over the currently active view, however it requires the currently active view as an input parameter and I cannot find a way to get at it from the App Delegate.

Self.Window.RootViewController returns Null, there is no current view or UIViewController visible that I can find from the delegate.

Any help is much appreciated.

Upvotes: 1

Views: 281

Answers (1)

Linuxios
Linuxios

Reputation: 35803

Instead of doing this, you need to use a different architecture, like notifications.

In the AppDelegate, where you were going to do this, replace it with this:

[[NSNotificationCenter defaultCenter] postNotificationName:@"showPleaseWaitAlert" object:nil];

Then, implement a method like this in your view controller:

-(void)showPleaseWait {
  //Show your dialog here
}

Then, in a method like viewDidLoad, do this:

[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showPleaseWait) name:@"showPleaseWaitAlert" object:nil]

Upvotes: 5

Related Questions