- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
小伙伴们:
在我的测试应用程序的 viewController 中有两个按钮,我称之为“否”的正确按钮,
另一个是"is"。两个按钮会调用两个不同的函数,而当
用户按下其中一个按钮,我想向用户显示一个警告以确认这一点。
我知道使用 UIAlertViewDelegate
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
但是有两个按钮,我很纳闷。我怎么知道按下了哪个按钮。
所以,请帮我解决这个问题,在此先感谢您!
最佳答案
当你创建一个UIAlertView
时,你可以为它设置一个标签
-(IBAction)yesButtonClick:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle: @"Cancel" otherButtonTitles:@"OK", nil];
alert.tag = 101;
[alert show];
}
-(IBAction)noButtonClick:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle: @"Cancel" otherButtonTitles:@"OK", nil];
alert.tag = 102;
[alert show];
}
在委托(delegate)方法中检查正在显示的警报
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == 101) {
// from YES button
}
else if (alertView.tag == 102) {
// from NO button
}
}
关于ios - UIAlertViewDelegate :clickedButtonAtIndex and two buttons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976471/
我是一名 Android 开发人员。 我想在我的代码中使用自定义 UIAlertViewDelegate。 类似演示 import UIKit class ViewController: UIView
我正在定义一个符合 UIAlertViewDelegate 的类: class PaymentAlert: NSObject, UIAlertViewDelegate { var orderI
我有一个非常简单的流程运行,在每一轮简单的游戏之后计算分数,更新标签和所有正常的,非常简单的东西。我有一个 UIAlertView 可以通知玩家他/她的表现。我使用 UIAlertViewDelega
我有实现 UIAlertViewDelegate 的 Controller 。在实现中我有: - (void)alertView:(UIAlertView *)alertView clickedBut
我是 Objective-C 的新手,我只是想弄清楚我是否可以使用 block 或选择器作为 UIAlertView 的 UIAlertViewDelegate 参数 - 哪个更合适? 我已经尝试了以
我正在尝试使用一种可选的委托(delegate)方法来扩展 UIAlertViewDelegate 协议(protocol)。 界面 @protocol HPAlertViewDelegate; @i
我正在使用 iPhone 的 Logo (MobileSubstrate 插件),并为我的 .h 文件 @interface MyClass : NSObject 和 - (void)alertVi
UIAlertViewDelegate 协议(protocol)定义了两个方法,alertView:clickedButtonAtIndex: 和 alertView:didDismissWithBu
在早期的 Objective-C 中,我们在 UIAlertView 中使用了 delegate:self,这样我们就可以在索引处调用类似 buttonclicked 的方法....但现在在 swif
我有一个从文件中读取的导入序列,解压缩包含的文件并为每个文件创建相应的核心数据实体。这整个过程发生在后台,并且已经为每个线程等创建了一个单独的上下文,所以一切正常。 事实证明,这个特定导入序列的一个理
几天来我一直在寻找这个问题的解决方案并找到了一些类似的帖子,但似乎没有人发布关于如何阻止我正在使用的实例获得 dealloc's 的明确答案.希望我只是错过了它,或者有人可以帮助我停止伤脑筋.. 我有
我在 ViewController 以外的类中遇到了 UIAlertView 委托(delegate)的问题。一切正常,直到用户单击 OK 按钮 - 然后应用程序崩溃并显示 Thread 1: EXC
小伙伴们: 在我的测试应用程序的 viewController 中有两个按钮,我称之为“否”的正确按钮, 另一个是"is"。两个按钮会调用两个不同的函数,而当 用户按下其中一个按钮,我想向用户显示一个
我们曾经在 ViewController.h 中使用 UIAlertViewDelegate 让我们的自定义警报按钮执行一个操作,比如在警报窗口中按下 Play Again 按钮使游戏重新开始。 我们
我添加了一个alertView来向用户显示警报消息(见下文) -(void)connectionAlert { UIAlertView *alert = [[UIAlertView alloc
我的应用程序中的多个 ViewController 必须显示相同的 UIAlertView 并以相同的方式执行 –alertView:clickedButtonAtIndex: 方法。我不想在多个文件
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预
我开始学习 Objective-C uikit,我遇到了一个问题。没有调用 UIAlertViewDelegate。谁能告诉我为什么?谢谢你! #import #import @interface
我有一个助手类,我想显示一个 UIAlertView,然后将执行一些 Web 服务操作。我想这样做,这样我就可以在其他地方重新使用警报 View 。 我是这样声明的: @interface FBLin
在发生以下情况之前,我以为我终于设法理解了委托(delegate)的概念:我更改了头文件以删除对委托(delegate)的引用,并且 Alert 仍然有效。唯一的区别是我丢失了代码提示。 //.h #
我是一名优秀的程序员,十分优秀!