Iphone dialog box Tool

Source: Internet
Author: User

In the project, I encapsulate the pop-up and click events in a tool class. It is important to implement the Protocol in the tool class when calling this tool class, the method of this Protocol is to tell the page which button of the dialog box is clicked, and then the page can respond to different events based on different values passed in. The Code is as follows:
. H file
[Cpp]
# Import <Foundation/Foundation. h>
 
@ Protocol myAlertviewutilDelegate <NSObject>
 
-(Void) myalertviewbuttonclik :( int) num;
 
@ End
 
@ Interface AlertViewUtil: NSObject <UIAlertViewDelegate> {
// Custom dialog box Protocol
Id <myAlertviewutilDelegate> utildelegate;
UIAlertView * myonealertview; // a dialog box with a button
UIAlertView * mytwoalertview; // dialog box with two buttons
UIAlertView * mythreealertview; // dialog box with three buttons
}
 
@ Property (nonatomic, retain) id <myAlertviewutilDelegate> utildelegate;
 
 
-(Void) alertviewutilone :( NSString *) buttontitleone addmessage :( NSString *) message;
-(Void) alertviewutiltwo :( NSString *) buttontitleone twobutton :( NSString *) buttontitletwo addmessage :( NSString *) message;
-(Void) alertviewutilthree :( NSString *) buttontitleone twobutton :( NSString *) buttontitletwo threebutton :( NSString *) buttontitlethree addmessage :( NSString *) message;
@ End

. M file
[Cpp]
# Import "AlertViewUtil. h"
 
 
@ Implementation AlertViewUtil
@ Synthesize utildelegate;
 
-(Void) dealloc {
[Utildelegate release];
[Super dealloc];
}
// Implement the button clicking method in the system conversation Basket Protocol
-(Void) alertView :( UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {
// Click the first alertview
If (alertView = myonealertview ){
If (buttonIndex = 0 ){
[Self. utildelegate myalertviewbuttonclik: 11];
}
[Myonealertview release];
}
// Click the second alertview.
Else if (alertView = mytwoalertview ){
If (buttonIndex = 0 ){
[Self. utildelegate myalertviewbuttonclik: 21];
}
Else if (buttonIndex = 1 ){
[Self. utildelegate myalertviewbuttonclik: 22];
}
[Mytwoalertview release];
}
// Click the third alertview.
Else if (alertView = mythreealertview ){
If (buttonIndex = 0 ){
[Self. utildelegate myalertviewbuttonclik: 31];
}
Else if (buttonIndex = 1 ){
[Self. utildelegate myalertviewbuttonclik: 32];
}
Else if (buttonIndex = 2 ){
[Self. utildelegate myalertviewbuttonclik: 33];
}

[Mythreealertview release];
}

}
 
// Alertview with only one button
-(Void) alertviewutilone :( NSString *) buttontitleone addmessage :( NSString *) message {
Myonealertview = [[UIAlertView alloc] initWithTitle: @ "prompt" message: message delegate: self cancelButtonTitle: nil otherButtonTitles: buttontitleone, nil];
[Myonealertview show];
}
 
// The alertview of the two buttons
-(Void) alertviewutiltwo :( NSString *) buttontitleone twobutton :( NSString *) buttontitletwo addmessage :( NSString *) message {
Mytwoalertview = [[UIAlertView alloc] initWithTitle: @ "prompt" message: message delegate: self cancelButtonTitle: nil otherButtonTitles: buttontitleone, buttontitletwo, nil];
[Mytwoalertview show];
}
 
// Alertview with three buttons
-(Void) alertviewutilthree :( NSString *) buttontitleone twobutton :( NSString *) buttontitletwo threebutton :( NSString *) buttontitlethree addmessage :( NSString *) message {
Response = [[UIAlertView alloc] initWithTitle: @ "prompt" message: message delegate: self cancelButtonTitle: nil otherButtonTitles: buttontitleone, buttontitletwo, buttontitlethree, nil]
[Mythreealertview show];
}
 
@ End



From RiverAM's column

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.