uiviewcontroller - dismissViewControllerAnimated:completion: on iOS 8 -
in ios <= 7, directly after calling dismissviewcontrolleranimated:completion:
result in presentedviewcontroller
being nil
. in ios 8, presentedviewcontroller
still points presented viewcontroller, right until completion block executed.
[self dismissviewcontrolleranimated:no completion:^{ //self.presentedviewcontroller nil }]; //self.presentedviewcontroller nil on ios 7, not nil on ios 8
so in ios 8 cannot rely on property presentedviewcontroller
in order find out viewcontroller top visible viewcontroller.
in ios 8, alerts need presented onto viewcontroller (which poses problem). not show if viewcontroller try present on presents viewcontroller.
if dismissed presented viewcontroller , show uialertcontroller
on top visible viewcontroller (by recursively searching last presentedviewcontroller
), of course not show log error message: "warning: attempt present on view not in window hierarchy!"
- is bug in ios 8 or new way?
- how can find out viewcontroller can present
uialertcontroller
on?
i found workaround find out viewcontroller can present alert upon:
@implementation uiviewcontroller (visibleviewcontroller) - (uiviewcontroller *)my_visibleviewcontroller { if ([self iskindofclass:[uinavigationcontroller class]]) { // not use method visibleviewcontroller presentedviewcontroller beingdismissed return [[(uinavigationcontroller *)self topviewcontroller] my_visibleviewcontroller]; } if ([self iskindofclass:[uitabbarcontroller class]]) { return [[(uitabbarcontroller *)self selectedviewcontroller] my_visibleviewcontroller]; } if (self.presentedviewcontroller == nil || self.presentedviewcontroller.isbeingdismissed) { return self; } return [self.presentedviewcontroller my_visibleviewcontroller]; } @end // show uialertcontroller, present on following viewcontroller: uiviewcontroller *visibleviewcontroller = [[uiapplication sharedapplication].delegate.window.rootviewcontroller my_visibleviewcontroller];
Comments
Post a Comment