Reputation: 16664
What I tried is:
- (void)main
{
NSError *err = (__bridge NSError *)error;
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"Error", nil)
message:err.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Do some thing here
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
}];
...
}
The problem is that there is no access to self.window
in my NSOperation
subclass.
Is there any other way to present alert controller?
Upvotes: 1
Views: 440
Reputation: 8954
UIApplicationDelegate
instance keeps window object, so you can get it and use for your purposes.
[[UIApplication sharedApplication].delegate window]
Also [UIApplication sharedApplication]
provides other methods which you may be useful to you:
- windows
- an array of all the windows;– keyWindow
- gives the window that is receiving keyboard input (or nil);If you are not creating additional windows, then using [[UIApplication sharedApplication].delegate window]
will be fine.
Upvotes: 1