UIAlert 查看 Objective C - 打开应用商店链接

发布于 2024-10-07 05:33:29 字数 509 浏览 0 评论 0原文

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!" 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301349397&mt=8"]];];
    [alert show];
    [alert release];

我正在尝试显示一个带有一个“确定”按钮和一个“购买完整版本”按钮的 UIAlertView。我怎样才能使上面的代码工作?

谢谢

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!" 
                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301349397&mt=8"]];];
    [alert show];
    [alert release];

I'm trying to display a UIAlertView with one "Ok" button and one "Buy Full Version" button. How can i make the above code work?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期情话 2024-10-14 05:33:29

您需要处理 UIAlertViewDelegate

另外,otherButtonTitles 只是用作标题的 NSString 对象的 va_list,您可以设置在 UIAlertViewDelegate< 中点击它们时会发生什么。 /code> 的 alertView:clickedButtonAtIndex: 方法:

- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger) index {
    if(index == 1) {
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301349397&amp;amp;amp;mt=8"]];
    }
}

不要忘记设置 delegate

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!" 
                                                            delegate:self
                                                   cancelButtonTitle:@"OK"
                                                   otherButtonTitles:@"Buy Full Version"];
[alert show];
[alert release];

You need to handle the button click in the UIAlertViewDelegate that you specify.

Also, otherButtonTitles is simply a va_list of NSString objects to use as titles, you set what happens when they are tapped in UIAlertViewDelegate's alertView:clickedButtonAtIndex: method:

- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger) index {
    if(index == 1) {
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301349397&amp;amp;amp;mt=8"]];
    }
}

Don't forget to set the delegate:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"An Alert!" 
                                                            delegate:self
                                                   cancelButtonTitle:@"OK"
                                                   otherButtonTitles:@"Buy Full Version"];
[alert show];
[alert release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文