iphone开发之使用ActionSheet

ActionSheet和AlertView比较相似都是给用户一个提示信息。它是从底部弹出。它通常用于确认潜在的危险或不能撤消的操作,如删除一个数据。

 为了使用ActionSheet我们需要在h文件中实现UIActionSheetDelegate协议。其中,我们常常需要实现: actionSheet:didDismissWithButtonIndex:

 该方法是ActionSheet消失的时候调用。



1.修改.h文件

@interface Hello_WorldViewController: UIViewController <UIActionSheetDelegate> {
"UITextField *txtField;
}

2.实现方法

-(IBAction)onClickButton:(id)sender {

   txtField.text = @"Hello World.";
   UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                initWithTitle:@"您确认清除文本框中的数据吗?" 
                                delegate:self 
                                cancelButtonTitle:@"取消" 
                                destructiveButtonTitle:@"确定" 
                                otherButtonTitles:nil];

  [actionSheet showInView:self.view];
  [actionSheet release];
}

//actionsheet关闭的时候触发
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
 if (buttonIndex == [actionSheet destructiveButtonIndex]) {
txtField.text = @""; "
}
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值