objective c - Present UIAlertController from NSOperation -
what 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 thing here [self.window.rootviewcontroller dismissviewcontrolleranimated:yes completion:nil]; }]; ... }
the problem there no access self.window
in nsoperation
subclass. there other way nowadays alert controller?
uiapplicationdelegate
instance keeps window object, can , utilize purposes.
[[uiapplication sharedapplication].delegate window]
also [uiapplication sharedapplication]
provides other methods may useful you:
- windows
- array of windows; – keywindow
- gives window receiving keyboard input (or nil); if not creating additional windows, using [[uiapplication sharedapplication].delegate window]
fine.
objective-c ios8 nsoperation uialertcontroller
No comments:
Post a Comment