Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize UIAlertController with UITableView or is there any default control available like this UI in Pages app?

I would like to implement a UIAlertViewController like this (Reference: Pages and Keynote app):

enter image description here.

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];
}
like image 715
SMS Avatar asked Jan 04 '16 14:01

SMS


People also ask

How does UIAlertController work?

method. UIKit displays alerts and action sheets modally over your app's content. In addition to displaying a message to a user, you can associate actions with your alert controller to give people a way to respond. For each action you add using the addAction(_:)


1 Answers

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.

like image 104
Léo Natan Avatar answered Oct 20 '22 00:10

Léo Natan