Three pop-up window modes in IOS and three pop-up window modes in IOS

Source: Internet
Author: User

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;

}];

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.