UIActionSheet
- #import "FirstViewController.h"
-
- @interface FirstViewController ()<UIActionSheetDelegate,UIAlertViewDelegate>
- @property (retain, nonatomic) IBOutlet UILabel *aLabel;
- @property (retain, nonatomic) IBOutlet UITextField *textField;
- @end
- @implementation FirstViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- }
- - (IBAction)upButton:(UIButton *)sender {
-
-
-
-
- UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"选择" delegate:self cancelButtonTitle:@"取消按钮" destructiveButtonTitle:@"确认按钮" otherButtonTitles:nil, nil nil];
- sheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
- sheet.title = @"请点击您的选择";
-
- [sheet addButtonWithTitle:@"添加的按钮"];
-
- sheet.destructiveButtonIndex = 0;
- [sheet showInView:self.view];
- [sheet release];
-
-
-
-
-
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"是否已满十八岁?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil nil];
- alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
-
-
-
-
- [alert show];
- [alert release];
- }
第一种 ActionSheet单独使用
- - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
-
- switch (buttonIndex) {
- case 0:
- self.aLabel.text = self.textField.text;
- break;
- case 1:
- break;
- case 2:
- NSLog(@"让你点你还真点");
- break;
- default:
- break;
- }
-
- }
第二种,单独使用UIAlertView
- -(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
- {
-
-
- switch (buttonIndex) {
- case 0:
- break;
- case 1:
- self.aLabel.text = self.textField.text;
- break;
- default:
- break;
- }
-
- }
第三种混合使用
- - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
-
- NSString *string=[NSString stringWithFormat:@"你选择了 %@",[actionSheet buttonTitleAtIndex:buttonIndex]];
-
- UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"输入账户和密码" message:string delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil nil];
- alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
-
-
-
-
-
- switch (buttonIndex) {
- case 0:
- [alert show];
- break;
- case 1:
- break;
- default:
- break;
- }
- [alert release];
-
- }
- - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
- {
-
-
- NSString * string=[NSString stringWithFormat:@"你点击了 %@",[alertView buttonTitleAtIndex:buttonIndex]];
-
- switch (buttonIndex) {
- case 0:
- break;
- case 1:
- self.aLabel.text = self.textField.text;
- break;
- default:
- break;
- }
-
- NSLog(@"%@",string);
-
-
- }
-
- <span style="background-color: rgb(255, 0, 0);"><span style="color:#99ff99;">最终效果:</span></span>
UIActionSheet,UIAlertView技术分享
原文:http://www.cnblogs.com/Yishu/p/4867331.html