uiactionsheet 代理_[iPhone开发之控件的使用]UIActionSheet的各种属性、方法及代理的使用-阿里云开发者社区...

#import "ActionSheetTestViewController.h"

@implementation ActionSheetTestViewController

/*

Tasks

Creating Action Sheets

– initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:

Setting Properties

delegate  property

title  property

visible  property

actionSheetStyle  property  无例

Configuring Buttons

– addButtonWithTitle:

numberOfButtons  property

– buttonTitleAtIndex:

cancelButtonIndex  property

destructiveButtonIndex  property

firstOtherButtonIndex  property

Displaying

– showFromTabBar:

– showFromToolbar:

– showInView:

Dismissing

– dismissWithClickedButtonIndex:animated:

*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

UILabel *numOfBtn = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 10.0, 30.0, 30.0)];

UILabel *titleOfBtn = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 10.0, 100.0, 30.0)];

UILabel *cancelBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(200.0, 10.0, 30.0, 30.0)];

UILabel *destructiveBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 50.0, 30.0, 30.0)];

UILabel *firstOtherBtnIndex = [[UILabel alloc]initWithFrame:CGRectMake(50.0, 50.0, 30.0, 30.0)];

UIActionSheet *actionSheetTest = [[UIActionSheet alloc]initWithTitle:@"ActionSheetTest"

delegate:self

cancelButtonTitle:@"CancelButton"

destructiveButtonTitle:@"RedButton"

otherButtonTitles:@"OtherButton1",@"OtherButton2",nil];

//看actionSheet是否可见,这是一个只读属性

BOOL a = actionSheetTest.visible;

NSLog(@"%d",a);

//不考虑指定索引的按钮的动作,可以设置是否有动画

[actionSheetTest dismissWithClickedButtonIndex:0 animated:NO];

//设置标题

actionSheetTest.title = @"ActionSheetTitle";

//通过给定标题添加按钮

[actionSheetTest addButtonWithTitle:@"addButtonWithTitle"];

//按钮总数

numOfBtn.text = [NSString stringWithFormat:@"%d",actionSheetTest.numberOfButtons];

//获取指定索引的标题

titleOfBtn.text = [actionSheetTest buttonTitleAtIndex:4];

//获取取消按钮的索引

cancelBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.cancelButtonIndex];

//获取红色按钮的索引

destructiveBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.destructiveButtonIndex];

//获取第一个其他按钮的索引

firstOtherBtnIndex.text = [NSString stringWithFormat:@"%d",actionSheetTest.firstOtherButtonIndex];

//设置actionSheet出现的方式

[actionSheetTest showInView:self.view];//or [actionSheetTest showFromTabBar:] or [actionSheetTest showFromToolBar:]

[self.view addSubview:numOfBtn];

[self.view addSubview:titleOfBtn];

[self.view addSubview:cancelBtnIndex];

[self.view addSubview:destructiveBtnIndex];

[self.view addSubview:firstOtherBtnIndex];

[actionSheetTest release];

[numOfBtn release];

[titleOfBtn release];

[cancelBtnIndex release];

[destructiveBtnIndex release];

[firstOtherBtnIndex release];

[super viewDidLoad];

}

/*

// Override to allow orientations other than the default portrait orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

// Return YES for supported orientations

return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

*/

- (void)didReceiveMemoryWarning {

// Releases the view if it doesn't have a superview.

[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

}

- (void)viewDidUnload {

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}

- (void)dealloc {

[super dealloc];

}

#pragma mark -- UIActionSheetDelegate --

//根据被点击按钮的索引处理点击事件

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

NSLog(@"clickedButtonAtIndex:%d",buttonIndex);

}

//ActionSheet已经消失时

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

NSLog(@"didDismissWithButtonIndex:%d",buttonIndex);

}

//ActionSheet即将消失时

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值