一、基本用法
UIActionSheet提供了从屏幕底部向上滚动的菜单,同UIAlertView一样,它也是一个模态对话框
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[self window] makeKeyAndVisible];
UIActionSheet* alert = [[UIActionSheet alloc] initWithTitle:@"请选择您喜欢的颜色:"
delegate:nil
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"红色",@"橙色",@"黄色",@"蓝色",@"紫色",@"白色",@"黑色",nil];
[alert showInView:[self window]];
[alert release];
return YES;
}
二、获取点击了那一项(委托)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[self window] makeKeyAndVisible];
UIActionSheet* alert = [[UIActionSheet alloc] initWithTitle:@"请选择您喜欢的颜色:"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"红色",@"橙色",@"黄色",@"蓝色",@"紫色",@"白色",@"黑色",nil];
[alert showInView:[self window]];
[alert release];
return YES;
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
{
NSString *msg = [[NSString alloc] initWithFormat:@"你点击了第%d项",buttonIndex];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"通知" message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}