1

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

pkamb
  • 33,281
  • 23
  • 160
  • 191
Joey Carson
  • 2,973
  • 7
  • 36
  • 60
  • There is already a similar backwards-compatible wrapper which might interest you: https://github.com/steipete/PSTAlertController – Michał Ciuba Nov 19 '14 at 15:15
  • > the UIAlertController view itself will always show up at the top left (0, 0). - Do you have an image of this? – pkamb Nov 20 '14 at 00:22
  • Certainly, @pkamb. Edited the question to show the screenshot. I'm essentially having the UIAlertController create the view, and then adding the view from it as a subview of my UIController. – Joey Carson Nov 20 '14 at 01:29
  • I just added a similar question here: http://stackoverflow.com/questions/27028983/uialertcontroller-is-moved-to-buggy-position-at-top-of-screen-when-it-calls-pre – pkamb Nov 20 '14 at 01:40
  • I created a ShowSystemAlert class that handles old and new versions of the alert. I documented it here. http://www.wellgolly.com/?p=2010 – JScarry Nov 20 '14 at 02:00

0 Answers0