An exhaustive description of Uialertview and Uialertcontroller for iOS development

Source: Internet
Author: User
Tags deprecated

This article will explain the usage of Uialertview and Uialertcontroller in iOS development from four aspects:

what is Uialertview and Uialertcontroller? Second, why should we use Uialertview or Uialertcontroller? Third, how to use Uialertview and Uialertcontroller? Iv. reading reminders.
what is Uialertview and Uialertcontroller?

In a word, in all mobile apps, the cue window that appears is usually written by Uialertview or Uialertcontroller, both of which are functionally identical.

Second, why should we use Uialertview or Uialertcontroller?

Good human-computer interaction can improve the user experience, the human-computer interaction function of the operating system is an important factor to determine the "friendliness" of the computer system. The human-computer interaction function mainly depends on the input and output of external devices and the corresponding software to complete. In the traditional period, the equipment which can be used for human-computer interaction mainly includes keyboard display, mouse, various pattern recognition devices and so on. The software that corresponds to these devices is the part of the operating system that provides human-computer interaction. Early human-computer interaction facilities were mainly keyboards and monitors. The operator enters the command via the keyboard, executes immediately after the operating system receives the command, and displays the result through the display. The commands can be scored in different ways, but the interpretation of each command is clear and unique. Today, all of the operations we do on the mobile side are performed on a touchscreen screen, and for better human-computer interaction, the engineer will display the operation information or cue information on the screen, and the user can decide which button to click according to his or her own judgment. In a word, it is better to use human-computer interaction to improve the user experience and product design quality.

third, how to use Uialertview and Uialertcontroller? 1. How to use Uialertview:
    //newly initialized alert view.Uialertview *alertview = [[Uialertview alloc] Initwithtitle:@"Edit"Message@"Please Modify the Info" Delegate: Self Cancelbuttontitle:@"Cancel"Otherbuttontitles:@"sure",@" Other", nil]; //Modify the data for the following//This property was inherited from the UIView, and you can use it to distinguish when a alertview have multiple VI EWAlertview.tag =Indexpath.row; //Adds a button to the receiver with the given title.[Alertview Addbuttonwithtitle:@"addbtn"]; /** Uialertviewstyle = below 4 kinds of uialertviewstyledefault, uialertviewstylesecuretextinput,//Password input box style UI Alertviewstyleplaintextinput,//Normal input frame style uialertviewstyleloginandpasswordinput//Account password box style*/    //An alert, that allows, the user to enter text. Available in IOS 5.0 and later.Alertview.alertviewstyle =Uialertviewstyleplaintextinput; //Returns The Text field at the given indexUitextfield *textfield = [Alertview textfieldatindex:0]; Textfield.text=Model.title; //The number of buttons on the alert view. (read-only)NSLog (@"The total number of buttons is:%ld", alertview.numberofbuttons); //Returns the title of the button at the given index.NSLog (@"The button title at the specified index:%@", [Alertview Buttontitleatindex:1]); //The index number of the Cancel button.NSLog (@"Index for the Cancel button is:%ld", Alertview.cancelbuttonindex); //-1 if no otherbuttontitles or initwithtitle: ... not usedNSLog (@"The index of the first other button is (read-only):%ld", Alertview.firstotherbuttonindex); //Show Uialertview[Alertview show];
some basic properties of Uialertview

/**//According to the index of the clicked button to handle the click event called when a button is clicked. The view'll be automatically dismissed after this call returns*/- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex;//Alertview is about to be displayed-(void) Willpresentalertview: (Uialertview *) Alertview;//Alertview events that have been shown-(void) Didpresentalertview: (Uialertview *) Alertview;//events When Alertview is about to disappear//This method was invoked before the animation begins and the view is hidden.-(void) Alertview: (Uialertview *) Alertview Willdismisswithbuttonindex: (Nsinteger) Buttonindex;//events executed when the Alertview has disappeared//This method was invoked after the animation ends and the view is hidden.-(void) Alertview: (Uialertview *) Alertview Diddismisswithbuttonindex: (Nsinteger) Buttonindex;//Alertview Event of the Cancel button//If not defined in the delegate, we simulate a click in the Cancel button-(void) Alertviewcancel: (Uialertview *) Alertview;

2. How to use Uialertcontroller:

* A total of three steps are required to use Uialertcontroller

* 1. Instantiate alert:alertcontrollerwithtitle

* 2. Instantiation button: Actionwithtitle

* 3. Display Alertcontroller:presentviewcontroller

//1. Instantiating Alert:alertcontrollerwithtitleUialertcontroller *alertcontrol = [Uialertcontroller alertcontrollerwithtitle:@"Edit"Message@"Please modify the menu name:"Preferredstyle:uialertcontrollerstylealert];//2. Instantiate button: Actionwithtitle//to prevent circular referencing between block and controller, we need __weak to prevent__weaktypeof(alert) Walert =alert; [Alert addaction:[uialertaction Actionwithtitle:@"Determine"Style:uialertactionstyledestructive handler:^ (Uialertaction *action) {        //When you click the OK button, the block is calledNSLog (@"%@", [wAlert.textFields.firstObject text]);    }]]; [Alert addaction:[uialertaction Actionwithtitle:@"Cancel"Style:uialertactionstylecancel Handler:nil]]; //Add a text box (can only be added to the Uialertcontrollerstylealert style, and if it is preferredstyle:uialertcontrollerstyleactionsheet crashes)[Alert addtextfieldwithconfigurationhandler:^ (Uitextfield *TextField) {Textfield.text=Model.title; //How to monitor text changes[TextField addtarget:self Action: @selector (textfieldsvaluedidchange:) FORCONTROLEVENTS:UICONTROLEVENTEDITINGC    Hanged];    }]; [Alert Addtextfieldwithconfigurationhandler:^ (Uitextfield *TextField) {Textfield.securetextentry= YES;//ciphertext form DisplayTextfield.text =Model.price; }];//3. Display Alertcontroller:presentviewcontroller[Self Presentviewcontroller:alert animated:yes completion:nil];
Basic use of Uialertcontroller

Iv. Reading Reminders

In Xcode's IOS8 SDK, Uialertview and Uialertcontroller are replaced by Uialertcontroller. The official library explains:"uialertview is deprecated. Use Uialertcontroller with a preferredstyle of Uialertcontrollerstylealert instead. "," Uiactionsheet is deprecated. Use Uialertcontroller with a preferredstyle of Uialertcontrollerstyleactionsheet instead. ". Illustrates the development of ios8+, Uialertview and Uiactionsheet are obsolete, uialertcontroller in a modular replacement to replace these two control functions and roles.

An exhaustive description of Uialertview and Uialertcontroller for iOS development

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.