Is there any way to encapsulate UIAlertController within another UIViewController?

333 views Asked by At

I'm fairly new to iOS, so please keep answers clear. I've been toying with encapsulating UIAlertController in another UIViewController to use it as a replacement for UIActionSheet as it's deprecated in iOS 8.

The idea would be a replacement for UIActionSheet that is backward and forward compatible, , call it ImmortalActionSheet for instance.

If the component is used in iOS 8 or greater, it can use UIAlertController, otherwise it would fall back to UIActionSheet. That would make it a backward and forward compatible action sheet to replace many action sheets around an application I'm working with. And yes I need to maintain backward compatibility.

I've prototyped this but for whatever reason, when I present ImmortalActionSheet, the UIAlertController view itself will always show up at the top left (0, 0). No matter if I change the center, it never moves.

-(void) loadView
{
     UIView * child = nil;
     if ( [UIAlertController class] )
     {
         UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Make Choice!!" message:@"Choose one!" preferredStyle:UIAlertControllerStyleActionSheet];
         for (UIAlertAction * action in actions ){
             [alertController addAction:action];
         }

         child = alertController.view;
         [self addChildViewController:alertController];
     }

     self.view = [[UIView alloc] init];
     self.view.backgroundColor = [UIColor clearColor];
     [self.view addSubview:child];
}

UIAlertController moved to a buggy position

0

There are 0 answers