ios8 - how can I present a UIAlertController above UIViewController.view.window -
now, created uiviewcontroller called viewcontroller, , add subview called maskview on viewcontroller via:
uiview *maskview = [[uiview alloc] initwithframe:cgrectmake(0, 0, screen_size.width, screen_size.height)]; [self.view.window addsubview:maskview];
and on maskview there button called "deletebtn", when click on deletebtn, want present uialertcontroller via:
uialertcontroller *alertcontroller = [uialertcontroller alertcontrollerwithtitle:nslocalizedstring(@"mybulb.confirmremove", @"") message:@"" preferredstyle:uialertcontrollerstylealert]; uialertaction *cancelaction = [uialertaction actionwithtitle:nslocalizedstring(@"cancel", @"取消") style:uialertactionstyledefault handler:nil]; uialertaction *confirmaction = [uialertaction actionwithtitle:nslocalizedstring(@"confirm", @"确定") style:uialertactionstyledefault handler:^(uialertaction *action) { }]; [alertcontroller addaction:cancelaction]; [alertcontroller addaction:confirmaction]; [self presentviewcontroller:alertcontroller animated:yes completion:nil];
but alertcontroller not present on topmost screen, below maskview, how can show alertcontroller above maskview added on uiviewcontroller.view.window?
thanks much!
finally fixed problem creating new window object , switch between window , default one, code this:
if ([uialertcontroller class]) { appdelegate *appdelegate = [uiapplication sharedapplication].delegate; uialertcontroller *alertcontroller = [uialertcontroller alertcontrollerwithtitle:nslocalizedstring(@"readus.org.title", @"alert title") message:@"" preferredstyle:uialertcontrollerstylealert]; uialertaction *cancelaction = [uialertaction actionwithtitle:nslocalizedstring(@"readus.org.cancel", @"取消") style:uialertactionstyledefault handler:^(uialertaction *action) { [appdelegate.window makekeyandvisible]; }]; uialertaction *confirmaction = [uialertaction actionwithtitle:nslocalizedstring(@"readus.org.confirm", @"确定") style:uialertactionstyledefault handler:^(uialertaction *action) { //do like... [appdelegate.window makekeyandvisible]; }]; [alertcontroller addaction:cancelaction]; [alertcontroller addaction:confirmaction]; [self.alertwindow makekeyandvisible]; [self.alertwindow.rootviewcontroller presentviewcontroller:alertcontroller animated:yes completion:nil]; }
and self.alertwindow defined as:
@property (strong, nonatomic) uiwindow *alertwindow; - (uiwindow *)alertwindow { if (!_alertwindow) { _alertwindow = [[uiwindow alloc] initwithframe:[uiscreen mainscreen].bounds]; uiviewcontroller *viewcontroller = [[uiviewcontroller alloc] init]; _alertwindow.rootviewcontroller = viewcontroller; } return _alertwindow; }
Comments
Post a Comment