When we want to show a view at any time in a non -view class, we need to add the displayed view to the sub -view of the current View, or use the current View PresentViewController, or PushViewContrller. These operations need to obtain the currently displayed ViewController.
// Get the ViewController displayed by the current screen
- (UIViewController *) getcurrentvc
{{
UIViewController *result = nil;
UiWindow * Window = [[UIApplication SharedApplication] keywindow];
if (Window.WindowLevel! = UIWINDOWLEVELNOLMAL)
{{
Nsarray *Windows = [[UIApplication SharedApplication] Windows];
For (uiwindow * tmpwin in windows)
{{
if (tmpwin.windowLevel == uiwindowlevelnormal)
{{
window = tmpwin;
Break;
}
}
}
UIView *FrontView = [[Window SubViews] ObjectAtIndex: 0];
id nextResponder = [FrontView NEXTRESPONDER];
if ([NextResponder iskindofclass: [UIViewController Class]])
Result = NextResponder;
else
result = window.rootViewController;
Return result;
}