Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIAertController Usage
changeAlert = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
UIAlertController* __weak weakAlert = changeAlert;
UIAlertAction *alertActionOk = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
UITextField *t = [[weakAlert textFields] firstObject];
DLog(@"%@",t.text);
[weakAlert dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction *alertActionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
DLog(@"%@",action);
}];
UIAlertAction *alertActionTest = [UIAlertAction actionWithTitle:@"Test" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
UITextField *t = [[weakAlert textFields] firstObject];
DLog(@"%@",t.text);
[weakAlert dismissViewControllerAnimated:YES completion:nil];
}];
[weakAlert addAction:alertActionOk];
[weakAlert addAction:alertActionCancel];
[weakAlert addAction:alertActionTest];
[weakAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.placeholder = @"pls";
}];
[self.viewController presentViewController:weakAlert animated:YES completion:nil]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment