IOS-UIAlertView and UIActionSheet
Two controls in IOS: UIAlertView and UIActionSheet
UIAlertView is a message box that appears in the center of the screen. This message box can be used for message prompts or different options.
UIActionSheet is a message box popped up at the bottom of the screen. Its function is similar to that of UIAlertView. However, apart from the different positions, the two have different appearances. In order to be able to respond to UIAlertView and UIActionSheet, you need to set the proxy, and the corresponding proxy needs to implement the corresponding protocol (UIAlertViewDelegate, UIActionSheetDelegate ). Implement the following two functions:
// Called when a button is clicked. The view will be automatically dismissed after this call returns- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;// Called when a button is clicked. The view will be automatically dismissed after this call returns- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
Sample Code
Proxy Implementation Protocol
@interface ViewController : UIViewController
Main Function Code
-(IBAction) onTextFieldEnd :( id) sender {[_ textTime resignFirstResponder]; // displayed dialog box # if 0 UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "TextContend" message: _ textTime. text delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: @ "Good", @ "Thanks", nil]; [alert show]; [alert release]; # else // the pop-up dialog box at the bottom of the dialog box UIActionSheet * sheet = [[UIActionSheet alloc] initWithTitle: @ "ActionSheet" delegate: self cancelButtonTitle: @ "cancelButtonTitle" comment: @ "OtherButton1", @ "OtherButton2", nil]; [sheet showInView: self. view]; [sheet release]; # endif} // response function-(void) alertView: (UIAlertView *) alertView clickedButtonAtIndex :( NSInteger) buttonIndex {NSString * strInfo = nil; strInfo = [[NSString alloc] initWithFormat: @ "you have pressed the [% @] button, the % d button", [alertView buttonTitleAtIndex: buttonIndex], buttonIndex]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "button response proxy function" message: strInfo delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show] [alert release]; [strInfo release];} // response function-(void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex {NSString * strInfo = nil; strInfo = [[NSString alloc] initWithFormat: @ "you have pressed the [% @] button, the % d button", [actionSheet buttonTitleAtIndex: buttonIndex], buttonIndex]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "button response proxy function" message: strInfo delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show] [alert release]; [strInfo release];}