【iPhone代码片段之一】UIActionSheet&UIAlertView的应用
2012-07-25 23:21
423 查看
类需要符合<UIActionViewDelegate>协议。
示例代码如下:
示例代码如下:
- (IBAction)buttonPressed:(id)sender { NSLog(@"buttonPressed"); UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"您要查看进度情况吗?" delegate:self//操作表的代理,按钮被按下时收到通知,然后回调协议中的相关方法 cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil]; [actionSheet showInView:self.view]; } -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{ NSString *msg = nil; UIAlertView *alert = nil; if(buttonIndex == [actionSheet destructiveButtonIndex]){ if(nameField.text.length>0){ msg = [[NSString alloc] initWithFormat:@"您歇会儿吧,%@,一切正常!",nameField.text]; }else{ msg = @"您歇会儿吧,一切正常!"; } alert = [[UIAlertView alloc] initWithTitle:@"搞定了" message:msg delegate:nil//不需要处理按钮按下事件,将委托设置为空 cancelButtonTitle:@"我知道了" otherButtonTitles: nil]; }else if(buttonIndex==[actionSheet cancelButtonIndex]){ msg = @"呜呜,没搞定呢,还在加班呢!"; alert = [[UIAlertView alloc] initWithTitle:@"没搞定" message:msg delegate:nil cancelButtonTitle:@"靠,继续搞吧!" otherButtonTitles: nil]; } [alert show]; [alert release]; [msg release]; }
相关文章推荐
- iphone开发 UIActionSheet(操作表) 和UIAlertView(警告)的用法
- iPhone起步-2:iPhone常用控件、UIActionSheet、UIAlertView (转)
- UI学习第三章 UISwitch   UISegment    UIAlertView    UIActionsheet
- Iphone之UIAlertView和UIActionSheet
- Iphone之UIAlertView和UIActionSheet
- UIAlertView&UIActionSheet
- UIActionSheet & UIAlertView
- UIAlertController(UIAlertView && UIActionSheet)
- IOS复习UIActionSheet&UIAlertView
- iPhone起步-2:iPhone常用控件、UIActionSheet、UIAlertView (转)
- UIAlertController  VS  UIAlertView and UIActionSheet
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- iOS UIAlertView 和 UIActionSheet 的使用
- UIAlertView,UIActionSheet的使用
- iOS开发 提示框- UIAlertController(是UIAlertView和UIActionSheet的合二为一)
- 2013-8-12练习[制作一个具有UIAlertView和UIActionSheet的登陆界面]
- IOS UIAlertController 弹框 (ios 9.0 后代替了UIAlertView弹框 和 UIActionSheet下弹框)
- 谈谈改变 UIAlertView 和 UIActionSheet 的颜色
- ios-消息弹框之UIAlertView, UIActionSheet以及UIAlertController小结