- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我创建了一个带有三个按钮的警报 View ——“注册”、“捐赠”、“取消”——当你点击注册或捐赠时,safari 应该打开特定的网站。但是,当我打开应用程序并单击任何按钮时,Safari 不会打开或执行任何操作,并且按钮的工作方式就像它们是取消按钮的不同版本一样。这是我的代码:
在 BlahBlah.h 中:
@interface BlahBlah: UIViewController <UITextFieldDelegate, UIAlertViewDelegate> {
}
@end
在 BlahBlah.m 中:
#define donate_tag 0
#import "BlahBlah.h"
@implementation BlahBlah
...
- (void) donate {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Donate"
message:@"Function doesn't work yet :(" delegate:nil cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Sign Up",@"Donate",nil];
alert2.tag = donate_tag;
[alert2 show];
[alert2 release];
}
...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag == donate_tag && buttonIndex == 1){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
}
else if(alertView.tag == donate_tag && buttonIndex == 2){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.yahoo.com"]];
}
}
...
@end
最佳答案
您需要告诉警报谁处理按钮的操作,也就是说,谁是警报 View 的“委托(delegate)
”。
由于与 UIAlertView 相关的所有内容都在您的“BlahBlah
” View Controller 中,因此在创建 alert2 之后,执行如下操作:
alert2.delegate = self;
或在您的 UIAlertView 实例化中声明它:
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:@"Donate"
message:@"Function doesn't work yet :(" delegate:self
cancelButtonTitle:@"Cancel" otherButtonTitles:@"Sign Up",@"Donate",nil];
关于ios - UIAlertView 不打开 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13201117/
这个问题已经有答案了: iOS How to dismiss UIAlertView with one tap anywhere? (2 个回答) 已关闭10 年前。 嗨,我是 Xcode 新手,ob
我试图在我的 swift 应用程序中显示一个 UIAlertView alert = UIAlertView(title: "", message: "bla",
问题是 iOS 键盘有时不再有反应。所以没有输入是可能的。如果我取消注释 clickedButtonAtIndex 中的第二个 UIAlertView,它工作正常。 原因可能在其他地方?我不知道...
我是 iPhone 开发人员的新人, 我想依次实现2个警报 View ,就像当用户按下删除按钮时,第一个警报 View 会询问你确定要删除吗?有两个按钮是 和否 现在,如果用户按 yes ,则第二个警
我想弄清楚为什么我的应用程序会崩溃。 它在带有 ios5.1 的模拟器中运行的 Xcode 4.4 中运行良好,但是当我切换到 xcode 4.5 和 ios6 时,我得到了 EXC_BAD_ACCE
我的 iOS 应用程序正在使用 Swift 2.0、RMUniversalAlert 版本 0.7 和 UIAlertView+Blocks 版本 0.9 当我在 Xcode 7 中构建它时,出现错误
我遇到了崩溃: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-
我在主线程上显示 UIAlertView 时遇到问题。我不知道为什么,但它不断崩溃,尽管我在主线程上运行。以下 block 位于后台线程上,但我在主线程上有警报,如下所示: void (^remove
我已将 iPhone 设置为横向模式,但当我尝试显示 UIAlertView 时,它会进入纵向模式。横向模式下如何显示? 最佳答案 在applicationDelegate.m文件的applicati
我使用 UIAlerView 子类创建自定义登录页面。现在,当我单击按钮时,它会打开 UIAlertView 我想根据按下的按钮更改主视图。 但是,由于 UIAlerView 的所有实现都在另一个类中
我弹出一个 UIAlertView 来询问用户是否确实要打开某个 URL。如果他们选择"is",我的应用程序会立即打开 URL 并发送到后台。当用户重新打开我的应用程序(使用多任务处理)时,警报 Vi
有没有办法将 .tag 添加到 UIAlertView 按钮?原因是,我向警报添加了一些动态按钮,这些按钮有时会出现在警报中,有时不会。我认为最好的方法是添加标签。有更好的方法吗? 警报中始终出现的选
我在 ib 中创建了一个自定义 uialertview,带有两个按钮和一个文本字段。然后我以这种方式创建一个 .h 和一个 .m: #import @interface DialogWelcome
看一下下面的代码,问题是AlertView没有显示出来,即使我在调试中看到代码已被执行。 请指教。 非常感谢 埃兰 -(void)displayABC:(id)sender { sta
我正在尝试更改 uialertview 的背景。一切工作正常,除了我添加到 uialert View 的背景图像不会在警报 View 内缩放。所以基本上你只能看到基于当前大小的背景图像的一部分。有什么
在我的应用程序中,我使用验证 key 通过 Wi-Fi 从服务器下载内容。如果许可证 key 错误或 wi-fi 不可用,我需要显示 UIAlert。我已经编写了用于显示警报 View 的男女混合代码
我创建了一个带有两个按钮和一个文本字段的 uialertview,如果文本字段为空,我希望禁用“确定”按钮。我如何获取 uibutton 对象来更改启用状态。 最佳答案 您可以使用从 UIContro
iPhone 应用程序开发人员您好, 我正在开发一个 iPhone 应用程序。该应用程序允许用户将图像上传到我的服务器。我想在alertView中显示上传进度。我需要一些示例代码来说明如何实现带有进度
有没有办法以编程方式隐藏 UIAlertView。我正在我的进度 View 中显示进度 View ,当进度 View = 1.0 时,我想隐藏 UIAlertView。 最佳答案 您可以做的是观察(使
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Is it possible to lay out 2 buttons vertically on UIAlertV
我是一名优秀的程序员,十分优秀!