Three pop-up window modes in IOS and three pop-up window modes in IOS
# Pragma mark method 1
/**
* Used in IOS7 and with a proxy
*/
-(Void) use1
{
// 1. Create an intermediate pop-up box with the "cancel" and "OK" buttons. Set the proxy to the current controller, and click "cancel" or "OK" for the Controller listener.
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "prompt" message: @ "click the image button" delegate: self cancelButtonTitle: @ "cancel" otherButtonTitles: @ "OK ", nil];
// 2. display on the screen
[Alert show];
}
# Click the button in the pop-up box that appears in pragma mark listening mode 1. The controller listens and clicks the cancel or OK button.
-(Void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex
{
// The index of the cancel button is 0 by default.
If (buttonIndex = 0) NSLog (@ "click Cancel ");
Else NSLog (@ "Click OK ");
}
# Pragma mark method 2
/**
* Used in ios8. No proxy is available. The operation to be executed when you click the button is placed in the block, so you do not need to set a proxy
*/
-(Void) use2
{
// 1. Create the bullet box controller. The UIAlertControllerStyleAlert style indicates that the bullet box is displayed in the center of the screen.
UIAlertController * alertVc = [UIAlertController alertControllerWithTitle: @ "prompt" message: @ "clicked Avatar" preferredStyle: UIAlertControllerStyleAlert];
// 2. Add the cancel button and click "cancel" in the block to perform the operation.
UIAlertAction * cancle = [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * action ){
NSLog (@ "click the cancel button ");
}];
UIAlertAction * confirm = [UIAlertAction actionWithTitle: @ "OK" style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * action ){
NSLog (@ "Click OK ");
}];
// 3. Add the cancel and OK buttons to the bullet box controller.
[AlertVc addAction: cancle];
[AlertVc addAction: confirm];
// 4. The controller displays the dialog box control and does not perform any operations upon completion.
[Self presentViewController: alertVc animated: YES completion: ^ {
Nil;
}];
}
# Pragma mark method 3
/**
* Used in ios8. No proxy is used. The only difference from method 2 is that the bullet box style changes to "UIAlertControllerStyleActionSheet", and the bullet box appears at the bottom of the screen.
*/
-(Void) use3
{
UIAlertController * alertVc = [UIAlertController alertControllerWithTitle: @ "prompt" message: @ "click the Avatar" preferredStyle: UIAlertControllerStyleActionSheet];
UIAlertAction * cancle = [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * action ){
NSLog (@ "click Cancel ");
}];
UIAlertAction * confirm = [UIAlertAction actionWithTitle: @ "OK" style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * action ){
NSLog (@ "Click OK ");
}];
[AlertVc addAction: cancle];
[AlertVc addAction: confirm];
[Self presentViewController: alertVc animated: YES completion: ^ {
Nil;
}];
}