`
xindrace
  • 浏览: 93665 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

UIAlertView的使用方法

    博客分类:
  • IOS
 
阅读更多

UIAlertView类似于C#中的模态对话框 或 Messagebox ,但是,ios中使用起来要麻烦得多。

下面这段代码是一段典型的应用:

UIAlertView *alert =[[UIAlertView allocinitWithTitle:@"hello" 

 message:@"ipad ,i come"

               delegate:self 

                  cancelButtonTitle:@"ok" 

        otherButtonTitles:nil];

[alert show];

[alert release];

 

 

 但是,如果复杂一点,就麻烦了,如果上面加上几个按钮,如:

 UIAlertView *alert =[[UIAlertView allocinitWithTitle:@"hello" 

 message:@"ipad ,i come"

               delegate:self 

                  cancelButtonTitle:@"ok" 

        otherButtonTitles:@"cancel",@"Ignore",nil ];

 

view 中会显示3个按钮,那怎么知道用户选择了哪个按钮呢?

 

步骤如下:

1、在修改.h文件,添加对alertview的处理,如下:

     @interface pad4ViewController : UIViewController 

<UIAlertViewDelegate>

{.。。

 

2、在.m文件中添加对alertview事件的响应,如下:  

 

  - (void) alertView:(UIAlertView *)alertview

clickedButtonAtIndex:(NSInteger)buttonIndex{

NSLog(@"%@",alertview.title);

}

 以上方法实现了当前.m中所有UIAlertView的事件响应,alertview指明是哪个view,buttonIndex指明是哪介按钮。

分享到:
评论

相关推荐

    左对齐UIAlertView

    UIAlertView左对齐且居中显示,兼容&gt;ios7,添加该两个文件,直接调用方法[alertView setTextAlignmentLeft];则可

    UIAlertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法

    UIAlertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法

    UIAlertView和UIActionSheet

    详细讲解UIAlertView和UIActionSheet的使用方法,以及开发中遇到的一些问题

    自定义带有UITableView的UIAlertView

    项目中用到带有带有UITableView的UIAlertView,刚开始的做法 是 UIAlertView 的基础上addsubview上UITableView,...重写了 layoutSubviews方法,可以用于横竖屏切换 ,UITableView的位置大小 在 UIAlertView内。

    iOS中UIAlertView警告框组件的使用教程

    初始化方法: 代码如下: – (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /**/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:...

    用UIAlertView写的一个登陆窗口

    用UIAlertView写的一个登陆窗口,里面对其原来的方法进行了扩展

    ios-MTAlertCategory - UIAlertView封装支持兼容7.0一下.zip

    简单的 UIAlert 封装 如果 (iOS )使用 UIAlertView 如果 (iOS &gt;= 8) UIAlertViewController. 使用方法和示例 UIAlertCategory * a = [[UIAlertCategory alloc] initWithTitle:@"警告" WithMessage:@"你有条...

    UIAlertView-Block-Short:带有阻止和显示消息的UIAlertView

    带有块的UIAlertView 不再需要使用委托方法。 用户可以使用Block创建UIAlertView。 用户传递参数时,必须以数组的方式传递按钮。 按钮索引将带有块。 [UIAlertView showAlertWithTitle: @" title " message: @" this...

    iOS中UIAlertView3秒后消失的两种实现方法

    一,效果图。... UIAlertView* alert = [[UIAlertView alloc]initWithTitle:nil message:@此信息3秒后消失 delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; [alert show]; [self p

    Android仿IOS UIAlertView对话框

    但是在使用的时候并不是很方面,有一些不足,于是我参照Android系统AlertDialog,使用参考链接中的布局文件和style文件,用自己的方法自定义了一下这个仿IOS上面UIAlertView的效果,这样的话让我们可以想使用系统...

    BMAlertHud:模仿系统的 UIAlertView ,但支持使用 NSAttributedString

    所以就仿照系统的 UIAlertView 原始功能,支持使用 NSAttributedString ,这样就可以自定义文本格式了,效果如下图; ###支持的功能: 支持 叠加 的弹出 多个 Alert框; 适配 iOS6、7、8, 弹框支持随着屏幕的 方向...

    BlockAlertsAnd-ActionSheets, 出色的UIAlertView和UIActionSheet替换灵感由 TweetBot.zip

    自从我第一次在应用中使用UIActionSheet或者UIAlertView时,我不喜欢它的实现方式。 如果在同一类中有两种警报,那么就很痛苦了,例如通过调用委托方法来完成所有。 我也不喜欢在按钮的事件中应该执

    自定义警报框

    自定义的UIAlertView,使用方法和系统的UIAlertView一样。

    UIAlertView封装支持兼容7.0

    作者yimouleng,源码UIAlertCategory,简单的 UIAlert 封装 如果 (iOS &lt;= 7)使用 UIAlertView 如果 (iOS &gt;= 8) UIAlertViewController. 使用方法和示例。

    ios-弹出视图,支持任何定制,整合UIAlertView和UIActionSheet两种风格的弹框,支持iOS7.zip

    整合了UIAlertView和UIActionSheet这两种系统风格的弹框,创建弹框再也不用兼容iOS8以前和iOS8以后了。代码也不会因为delegate而分离,直接接受Block回调。如果您觉得我的代码帮到了您,我会非常欣慰。同时如果您想...

    HYCategory:iOS开发中常用到的分类

    UIAlertView+Extension:增加UIAlertView的方法,例如使用block代替selector创建UIAlertView.UIImage+Gif:一个使用Gif的UIImage的分类。NSDate+Escort:一个方便使用NSDate的分类,添加了许多操作日期的方法,例如...

    JSPatch学习笔记-UI基础

    * 使用OC中的枚举类型 `Objective-C 里的常量不能直接在 JS 上使用,可以直接在 JS 上用具体值代替,或者在 JS 上重新定义同名的全局变量` 3. 类的扩展 * 重写方法(调用父类方法,需添加`ORIG`关键字) * 覆盖方法...

    对ASI post方式的封装

    使用方法: MyURLClass *post = [MyURLClass urlGo]; post.DataBlock = ^(NSData *data){ NSError *error; if (data == Nil) { UIAlertView *alt = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络...

    ios-UIAlertController.zip

    对UIAlertController进行了封装,iOS8 苹果增加了UIAlertController,把UIAlertView和...UIAlertView使用起来比较繁琐,需要实现代理,然后在代理的方法里对多个事件进行判断和处理。代码的阅读性和维护性不高。

Global site tag (gtag.js) - Google Analytics