Quantcast
Channel: User Burhanuddin Sunelwala - Stack Overflow
Viewing all articles
Browse latest Browse all 36

Answer by Burhanuddin Sunelwala for show alertController from a custom class

$
0
0

Well you just need to find the topmost view controller and present the alertcontroller from there.

UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;while (topController.presentedViewController) {    topController = topController.presentedViewController;}[topController presentViewController:alertController animated:YES completion:nil];

credits

Note: This is objective-c version of the code. Kindly convert it to swift accordingly.

SWIFT

let topController = UIApplication.sharedApplication().keyWindow!.rootViewController as UIViewControllerwhile (topController.presentedViewController) {    topController = topController.presentedViewController;}topController.presentViewController(alertController, animated:true, completion:nil)

Viewing all articles
Browse latest Browse all 36

Trending Articles