So I have a UIAlertController which needs to be presented on top of another view controller, so a child view controller. I can get the child view controller to display on top of the parent no problem, but I can't get the alert buttons to respond when I bring this child view controller to the front.
UIAlertController* alert = [AlertHelper createAlertWithTitle:title
message:message
cancelButton:nil
continueButtonText:Ok
continueAction:nil
cancelAction:nil];
alert.view.translatesAutoresizingMaskIntoConstraints = false;
[self addChildViewController:alert];
alert.view.frame = self.view.bounds;
[self.view addSubview:alert.view];
[alert didMoveToParentViewController:self];
[alert.view.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
[alert.view.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor].active = YES;
UIAlertControlleris a specialized controller that makes use ofUIAlertAction.Worth noting from Apple's docs:
While you may not be subclassing it (you didn't provide your
AlertHelpercode), you're clearly not using it "as-is."Instead, you probably want to design your own "simulated" alert controller.
Here's a quick example...
AlertHelper.h
AlertHelper.m
and an example view controller:
** ViewController.h**
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController @end
** ViewController.m**
Output: