iOS Development Xcode Learning 014: Warning dialogs and waiting prompts

Source: Internet
Author: User

The learning source of this article is: http://study.163.com/course/introduction/1002858003.htm

This project file implements the function:

1, warning dialog and waiting for the concept of the prompt

2. warning dialog boxes and the properties of the wait prompt

3, warning dialog and waiting for the use of the prompt

===========================viewcontroller.h Script ==============================  

@interface Viewcontroller:uiviewcontroller <UIAlertViewDelegate>

{

//Define a warning dialog box view Object

uialertview* _alertview;

//wait for prompt object

When you download or load a larger file, you can display this control in a prompt wait state

uiactivityindicatorview* _activityindicatorview;

}

@property (retain,nonatomic) uialertview* Alertview;

@property (retain,nonatomic) Uiactivityindicatorview * Activityindicatorview;

@end

===========================VIEWCONTROLLER.M Script ==============================

@interface Viewcontroller ()

@end

@implementation Viewcontroller

Synchronization of attributes and member variables

@synthesize Alertview = _alertview;

@synthesize Activityindicatorview = _activityindicatorview;

-(void) Viewdidload {

[Super Viewdidload];

Additional setup after loading the view, typically from a nib.

for (int i = 0; i < 2; i++) {

uibutton* btn = [UIButton buttonwithtype:uibuttontyperoundedrect];

Btn.frame = CGRectMake (100, 40);

if (i = = 0) {

[BTN settitle:@] warning dialog box "Forstate:uicontrolstatenormal";

}

else if (i = = 1)

{

[BTN settitle:@ "Wait indicator" forstate:uicontrolstatenormal];

}

Btn.tag = 101 + i;

[Btn addtarget:self Action: @selector (PRESSBTN:) forcontrolevents:uicontroleventtouchupinside];

[Self.view ADDSUBVIEW:BTN];

}

}

-(void) Pressbtn: (uibutton*) btn

{

//Warning dialog box

if (Btn.tag = = 101) {

//Create warning dialog box

P1: Dialog box title

P2: Tip Information

P3: Proxy object for handling button events

P4: Cancels the text of the button

P5: Other button text

P6 ...: Add another button

PLast: Indicates the end of the button add

Two buttons across the row, with a plurality of vertical rows

_alertview = [[Uialertview alloc] initwithtitle:@ "Warning"

message:@ "Your phone is too low and will shut down, please save the data."

Delegate:self

cancelbuttontitle:@ "Cancel" //Cancel button always last

otherbuttontitles:@ "OK", @ "one", @ "all", nil];

//Display dialog box

[_alertview show];

}

//Create a wait prompt

else if (Btn.tag = = 102)

{

//width and height are not changeable

_activityindicatorview = [[Uiactivityindicatorview alloc] Initwithframe:cgrectmake (100, 300, 80, 80)];

//SET hint style: small gray, small white, white

_activityindicatorview.activityindicatorviewstyle = uiactivityindicatorviewstylewhitelarge;// Uiactivityindicatorviewstylewhite;//uiactivityindicatorviewstylegray;

Self.view.backgroundColor = [Uicolor blackcolor];

[Self.view Addsubview:_activityindicatorview];

//Start the animation and display

[_activityindicatorview startanimating];

//Stop waiting for animations and hide

[_activityindicatorview stopanimating];

}

}

Call this function when you click the button in the dialog box

P1: Dialog Box object itself

P2: Index of the button

-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex

{

NSLog (@ "index =%ld\n", buttonindex);

}

The dialog box is about to disappear and this function is called

-(void) Alertview: (Uialertview *) Alertview Willdismisswithbuttonindex: (Nsinteger) Buttonindex

{

NSLog (@ "About to disappear");

}

The dialog box has disappeared and this function is called

-(void) Alertview: (Uialertview *) Alertview Diddismisswithbuttonindex: (Nsinteger) Buttonindex

{

NSLog (@ "dialog box has disappeared");

}

Program Run Result:

Button

Warning dialog box (2 buttons: horizontal)

Warning dialog box (4 buttons: vertical)

Wait Indicator: (white style)

Learning Summary:

    • Emphasis: The concept of warning dialogs and waiting reminders
    • Difficulty: Warning dialogs and the use of the wait prompt

Source Link Address: Https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA Password: 7t1l

iOS Development Xcode Learning 014: Warning dialogs and waiting prompts

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.