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 = @""; "
}
}
本文详细介绍了iOS开发中ActionSheet和AlertView的区别,并提供了如何在代码中使用它们的示例。重点突出了如何在面对需要用户确认的操作时,正确选择并实现这些提示组件,确保用户体验的同时进行必要的数据保护。

1997

被折叠的 条评论
为什么被折叠?



