[iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用
[c-sharp]view plaincopy #import"ActionSheetTestViewController.h" @implementationActionSheetTestViewController /* Tasks CreatingActionSheets –initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles: SettingProperties delegateproperty titleproperty visibleproperty actionSheetStyleproperty无例 ConfiguringButtons –addButtonWithTitle: numberOfButtonsproperty –buttonTitleAtIndex: cancelButtonIndexproperty destructiveButtonIndexproperty firstOtherButtonIndexproperty Displaying –showFromTabBar: –showFromToolbar: –showInView: Dismissing –dismissWithClickedButtonIndex:animated: */ //ImplementviewDidLoadtodoadditionalsetupafterloadingtheview,typicallyfromanib. -(void)viewDidLoad{ UILabel*numOfBtn=[[UILabelalloc]initWithFrame:CGRectMake(10.0,10.0,30.0,30.0)]; UILabel*titleOfBtn=[[UILabelalloc]initWithFrame:CGRectMake(50.0,10.0,100.0,30.0)]; UILabel*cancelBtnIndex=[[UILabelalloc]initWithFrame:CGRectMake(200.0,10.0,30.0,30.0)]; UILabel*destructiveBtnIndex=[[UILabelalloc]initWithFrame:CGRectMake(10.0,50.0,30.0,30.0)]; UILabel*firstOtherBtnIndex=[[UILabelalloc]initWithFrame:CGRectMake(50.0,50.0,30.0,30.0)]; UIActionSheet*actionSheetTest=[[UIActionSheetalloc]initWithTitle:@"ActionSheetTest" delegate:self cancelButtonTitle:@"CancelButton" destructiveButtonTitle:@"RedButton" otherButtonTitles:@"OtherButton1",@"OtherButton2",nil]; //看actionSheet是否可见,这是一个只读属性 BOOLa=actionSheetTest.visible; NSLog(@"%d",a); //不考虑指定索引的按钮的动作,可以设置是否有动画 [actionSheetTestdismissWithClickedButtonIndex:0animated:NO]; //设置标题 actionSheetTest.title=@"ActionSheetTitle"; //通过给定标题添加按钮 [actionSheetTestaddButtonWithTitle:@"addButtonWithTitle"]; //按钮总数 numOfBtn.text=[NSStringstringWithFormat:@"%d",actionSheetTest.numberOfButtons]; //获取指定索引的标题 titleOfBtn.text=[actionSheetTestbuttonTitleAtIndex:4]; //获取取消按钮的索引 cancelBtnIndex.text=[NSStringstringWithFormat:@"%d",actionSheetTest.cancelButtonIndex]; //获取红色按钮的索引 destructiveBtnIndex.text=[NSStringstringWithFormat:@"%d",actionSheetTest.destructiveButtonIndex]; //获取第一个其他按钮的索引 firstOtherBtnIndex.text=[NSStringstringWithFormat:@"%d",actionSheetTest.firstOtherButtonIndex]; //设置actionSheet出现的方式 [actionSheetTestshowInView:self.view];//or[actionSheetTestshowFromTabBar:]or[actionSheetTestshowFromToolBar:] [self.viewaddSubview:numOfBtn]; [self.viewaddSubview:titleOfBtn]; [self.viewaddSubview:cancelBtnIndex]; [self.viewaddSubview:destructiveBtnIndex]; [self.viewaddSubview:firstOtherBtnIndex]; [actionSheetTestrelease]; [numOfBtnrelease]; [titleOfBtnrelease]; [cancelBtnIndexrelease]; [destructiveBtnIndexrelease]; [firstOtherBtnIndexrelease]; [superviewDidLoad]; } /* //Overridetoalloworientationsotherthanthedefaultportraitorientation. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ //ReturnYESforsupportedorientations return(interfaceOrientation==UIInterfaceOrientationPortrait); } */ -(void)didReceiveMemoryWarning{ //Releasestheviewifitdoesn'thaveasuperview. [superdidReceiveMemoryWarning]; //Releaseanycacheddata,images,etcthataren'tinuse. } -(void)viewDidUnload{ //Releaseanyretainedsubviewsofthemainview. //e.g.self.myOutlet=nil; } -(void)dealloc{ [superdealloc]; } #pragmamark--UIActionSheetDelegate-- //根据被点击按钮的索引处理点击事件 -(void)actionSheet:(UIActionSheet*)actionSheetclickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"clickedButtonAtIndex:%d",buttonIndex); } //ActionSheet已经消失时 -(void)actionSheet:(UIActionSheet*)actionSheetdidDismissWithButtonIndex:(NSInteger)buttonIndex{ NSLog(@"didDismissWithButtonIndex:%d",buttonIndex); } //ActionSheet即将消失时 -(void)actionSheet:(UIActionSheet*)actionSheetwillDismissWithButtonIndex:(NSInteger)buttonIndex{ NSLog(@"willDismissWithButtonIndex:%d",buttonIndex); } // -(void)actionSheetCancel:(UIActionSheet*)actionSheet{ NSLog(@"actionSheetCancel"); } //ActionSheet已经显示时 -(void)didPresentActionSheet:(UIActionSheet*)actionSheet{ NSLog(@"didPresentActionSheet%@",actionSheet); } //ActionSheet即将显示时 -(void)willPresentActionSheet:(UIActionSheet*)actionSheet{ NSLog(@"willPresentActionSheet%@",actionSheet); }
@end
原文转载:http://blog.csdn.net/banyingli/article/details/6167561
@end
原文转载:http://blog.csdn.net/banyingli/article/details/6167561
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。