I would like to implement a UIAlertViewController
like this (Reference: Pages and Keynote app):
I have implemented a custom tableview and presented the view by mimicking the UIAlertViewController
. But I cannot achieve a similar UI as above. Is there any default controller available for this?
-(void)share:(id)sender
{
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
AlertViewController *renameCntrl = [self.storyboard instantiateViewControllerWithIdentifier:AlertTblViewidentifier];
renameCntrl.optionViewDelegate = self;
renameCntrl.providesPresentationContextTransitionStyle = YES;
renameCntrl.definesPresentationContext = YES;
[renameCntrl setModalPresentationStyle:UIModalPresentationOverCurrentContext];
[self presentViewController:renameCntrl animated:YES completion:nil];
}
UIAlertController
has a private contentViewController
property which allows you to set any UIViewController
subclass as part of the alert controller. It works well with both action sheet or alert styles. You can mix content view controller with other alert actions.
This is how UIActivityViewController
, the Airdrop preview controller, etc. are implemented.
Best practice is to subclass UIAlertController
, and in either initWithNibName:bundle:
or viewDidLoad
, use setValue:forKey:
to set the contentViewController
property. Don't forget to set the preferredContentSize
for your content view controller.