ActionSheet和AlertView比较相似都是给用户一个提示信息。它是从底部弹出。它通常用于确认潜在的危险或不能撤消的操作,如删除一个数据。
2.实现方法
为了使用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 = @""; "
}
}