iphone之ActionSheet介绍

              ActionSheet和AlertView比较相似,都是给用户一个提示信息。但是它是从底部弹出。它通常用于确认潜在的危险或不能撤销的操作。比如删除一条数据。我们使用ActionSheet时,需要在h文件中实现UIActionSheetDelegate协议。

通常我们需要实现:actionSheet:didDismissWithButtonIndex:该方法是ActionSheet消失的时候调用。

          下面我写一个测试例子,先看效果图

                                                

 

源码:

头文件:

#import <UIKit/UIKit.h>

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

@property (nonatomic, retain) IBOutlet UITextField *txtField;

-(IBAction)onClickButton:(id)sender;

@end


源文件:

@implementation Hello_WorldViewController


@synthesize txtField;


-(IBAction)onClickButton:(id)sender 
{
		
UIActionSheet *actionSheet = [[UIActionSheet alloc] 
 initWithTitle:@"您确认清除文本框中的数据吗?" 
								  delegate:self 
								  cancelButtonTitle:@"取消" 
								  destructiveButtonTitle:@"确定" 
								  otherButtonTitles:nil];
		
[actionSheet showInView:self.view];
	
[actionSheet release];	

}


-(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、付费专栏及课程。

余额充值