IAlertView*alert =[[UIAlertViewalloc]initWithTitle:@"hello"
message:@"ipad ,i come"
delegate:self
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alertshow];
[alertrelease];
但是,如果复杂一点,就麻烦了,如果上面加上几个按钮,如:
UIAlertView*alert =[[UIAlertViewalloc]initWithTitle:@"hello"
message:@"ipad ,i come"
delegate:self
cancelButtonTitle:@"ok"
otherButtonTitles:@"cancel",@"Ignore",nil];
view 中会显示3个按钮,那怎么知道用户选择了哪个按钮呢?
步骤如下:
在.m文件中添加对alertview事件的响应,如下: - (void) alertView:(UIAlertView*)alertview
clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0)
{
NSLog(@"%@",alertview.title);
}
}
如果此类中有多个弹出框那该如何区分是那个弹出框呢
利用tag
UIAlertView *errorDialogs= [[UIAlertView
alloc]initWithTitle:@"订单创建失败" message: [orderresult objectForKey:@"remark"]
delegate:self cancelButtonTitle:@"返回"
otherButtonTitles:nil,nil ];
errorDialogs.tag=3;
[errorDialogs
show];
[errorDialogs release];
然后在判断的时候这样子
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0) {
if(alertView.tag ==
3)
{
//[self.navigationController
popViewControllerAnimated:YES];
}
}
}
以上方法实现了当前.m中所有UIAlertView的事件响应,alertview指明是哪个view,buttonIndex指明是哪介按钮。
分享到:
相关推荐
UIAlertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
iPhone入门 - UIAlertView用法
详细讲解UIAlertView和UIActionSheet的使用方法,以及开发中遇到的一些问题
基于关联和block写的UIAlertView回调.一些关联的基本用法。
使用方法和示例 UIAlertCategory * a = [[UIAlertCategory alloc] initWithTitle:@"警告" WithMessage:@"你有条警告"]; [a addButton:ALERT_BUTTON_OK WithTitle:@"好的" WithAction:^(void *action) { ...
1. 最简单的用法 初始化方法: 代码如下: – (instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /**/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle ...
带有块的UIAlertView 不再需要使用委托方法。 用户可以使用Block创建UIAlertView。 用户传递参数时,必须以数组的方式传递按钮。 按钮索引将带有块。 [UIAlertView showAlertWithTitle: @" title " message: @" this...
自从我第一次在应用中使用UIActionSheet或者UIAlertView时,我不喜欢它的实现方式。 如果在同一类中有两种警报,那么就很痛苦了,例如通过调用委托方法来完成所有。 我也不喜欢在按钮的事件中应该执
但是在使用的时候并不是很方面,有一些不足,于是我参照Android系统AlertDialog,使用参考链接中的布局文件和style文件,用自己的方法自定义了一下这个仿IOS上面UIAlertView的效果,这样的话让我们可以想使用系统...
所以就仿照系统的 UIAlertView 原始功能,支持使用 NSAttributedString ,这样就可以自定义文本格式了,效果如下图; ###支持的功能: 支持 叠加 的弹出 多个 Alert框; 适配 iOS6、7、8, 弹框支持随着屏幕的 方向...
作者yimouleng,源码UIAlertCategory,简单的 UIAlert 封装 如果 (iOS <= 7)使用 UIAlertView 如果 (iOS >= 8) UIAlertViewController. 使用方法和示例。
主要介绍了iOS中UIAlertView3秒后消失的两种实现方法,实现方法涉及到NSTimer和PerformSelector:withObject:afterDelay:方法的结合使用,需要的朋友可以参考下
自定义的UIAlertView,使用方法和系统的UIAlertView一样。
整合了UIAlertView和UIActionSheet这两种系统风格的弹框,创建弹框再也不用兼容iOS8以前和iOS8以后了。代码也不会因为delegate而分离,直接接受Block回调。如果您觉得我的代码帮到了您,我会非常欣慰。同时如果您想...
简单的 Popover 替换原生 UIAlertView。 要求 Xcode 6 或更高版本 苹果LLVM编译器 iOS 6.0 或更高版本 弧 演示 在 Xcode 中构建并运行TYSimplePopoverDemo项目。 安装 将TYSimplePopoverViewController.h和...
用法 要运行示例项目,请克隆存储库,然后首先从Example目录运行pod install 。 不显示任何动作警报 [ARNAlert showNoActionAlertWithTitle: @" no action title " message: @" no action message " buttonTitle: @...
枪械警报GUNAlert 是 UIAlertView 和 UIAlertController 的简单包装器。 适用于需要与 iOS 版本 < 8 保持向后兼容性的应用程序。它被设计为适用于大多数常见用例的简单解决方案。用法例子要运行示例项目, pod ...
Apple 的 UIAlertView 的基于块的替代品。 用法: 只需将 MSSAlertViewController.h/.m 添加到您的项目中,您就可以开始使用了! 这是一个基本的“仅确定”警报: MSSAlertViewController *alert = ...
用法 要运行示例项目, pod install克隆 repo,然后从 Example 目录运行pod install 。 安装 TAlertView 可通过。 要安装它,只需将以下行添加到您的 Podfile 中: pod "TAlertView" 如何使用它 简单的 [[...
使用方法: MyURLClass *post = [MyURLClass urlGo]; post.DataBlock = ^(NSData *data){ NSError *error; if (data == Nil) { UIAlertView *alt = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络...