IOS development and ios development tutorial

Source: Internet
Author: User

IOS development and ios development tutorial
Traditional alertView

-(Void) alertView {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "warning" message: @ "Your operation is invalid. Do you want to continue?" delegate: nil cancelButtonTitle: @ "cancel" otherButtonTitles: @ "OK", nil]; alert. alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alert show];}

Traditional actionSheet
-(Void) actionSheet {UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle: @ "Warning: Your operation is invalid. Do you want to continue?" delegate: nil cancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "OK" otherButtonTitles: @ "close", nil]; [sheet showInView: self. view];}

UIAlertController = UIAlertView + UIActionSheet
-(Void) alertController {// dangerous operation: pop-up reminder // 1. UIAlertView // 2. UIActionSheet // start with iOS8: UIAlertController = UIAlertView + UIActionSheet UIAlertController * alert = [UIAlertController alertControllerWithTitle: @ "warning" message: @ "Your operation is invalid, do you want to continue? "preferredStyle: UIAlertControllerStyleAlert]; // Add button _ weak typeof (alert) weakAlert = alert; [alert addAction: [UIAlertAction actionWithTitle: @" OK "style: UIAlertActionStyleDestructive handler: ^ (UIAlertAction * action) {NSLog (@ "click the OK button -- % @-% @", [weakAlert. textFields. firstObject text], [weakAlert. textFields. lastObject text]);}]; [alert addAction: [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * action) {NSLog (@ "click the cancel button") ;}]]; [alert addAction: [UIAlertAction actionWithTitle: @ "other" style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * action) {NSLog (@ "Click other buttons") ;}]]; // Add the text box [alert addTextFieldWithConfigurationHandler: ^ (UITextField * textField) {textField. textColor = [UIColor redColor]; textField. text = @ "123"; [textField addTarget: self action: @ selector (usernameDidChange :) forControlEvents: UIControlEventEditingChanged]; // [[nsicationicationcenter defacenter center] addObserver: self selector: @ selector (usernameDidChange :) name: UITextFieldTextDidChangeNotification object: textField] ;}]; [alert addTextFieldWithConfigurationHandler: ^ (UITextField * textField) {textField. secureTextEntry = YES; textField. text = @ "123";}]; [self presentViewController: alert animated: YES completion: nil];}-(void) usernameDidChange :( UITextField *) username {NSLog (@ "% @", username. text );}

Other operations
-(Void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {UIAlertController * alert = [UIAlertController alertControllerWithTitle: @ "warning" message: @ "Your operation is invalid, do you want to continue? "preferredStyle: UIAlertControllerStyleActionSheet]; // set the item alert to which popover points. popoverPresentationController. barButtonItem = self. navigationItem. leftBarButtonItem; // Add button [alert addAction: [UIAlertAction actionWithTitle: @ "OK" style: UIAlertActionStyleDestructive handler: ^ (UIAlertAction * action) {NSLog (@ "Click OK") ;}]]; [alert addAction: [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: ^ (UIAlertAction * action) {NSLog (@ "click the cancel button") ;}]]; [self presentViewController: alert animated: YES completion: nil] ;}// UIAlertControllerStyleActionSheet Usage Note // 1. no text box // 2. in iPad, you must use popover to display // Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert // you can only add Text boxes to views in the UIAlertControllerStyleAlert style.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.