单击按钮后弹出警报将永远消失
我对 UIAlertView 的编程有点陌生。我的想法是做一个弹出窗口,在应用程序启动时显示,除了默认的关闭按钮之外,还有两个按钮。 其中一个按钮是应用程序商店的链接,另一个按钮是永远关闭该弹出窗口。 除了最后一个按钮之外,我已经完成了所有操作。 有什么帮助吗?
谢谢你!
- (void)viewDidLoad {
alert = [[UIAlertView alloc] initWithTitle:@"Rate!" message:@"Your rate is much apreciated" delegate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"Okay! ", @"No, Thanks!", nil ];
[alert show];
[alert release];
}
-(void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
}
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/pt/app/designertools/id444778173?mt=8#" ]];
}
}
I'm kinda new on programming UIAlertView's. What i had in mind was to do a Popup that shows on launch of the application with two more buttons besides the default dismiss button.
One of the buttons would be a link to the appstore and the other would be to dismiss that popup forever.
I've already done everything besides the last button.
Any help?
Thank You!
- (void)viewDidLoad {
alert = [[UIAlertView alloc] initWithTitle:@"Rate!" message:@"Your rate is much apreciated" delegate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"Okay! ", @"No, Thanks!", nil ];
[alert show];
[alert release];
}
-(void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
}
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/pt/app/designertools/id444778173?mt=8#" ]];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您似乎正在发出警报,以在应用程序商店中对您的应用程序进行评分,而不是回答您的直接(技术)问题,我将尝试解决更大的问题。您应该考虑使用现有的开源解决方案来处理提示用户进行评论的功能,您可以控制诸如启动多少次/天后提示他们之类的功能。
我可以推荐 Arash Pyan 的 Appirater。它的作用是自动处理应用程序的评级部分。它将用户直接带入您的应用程序的评论页面,并且非常可定制。新开发人员的最佳解决方案!它可以在 GitHub 上找到。
demosthenese 的 iRate 是一个类似的解决方案,但更干净并且支持快速应用程序切换。
请改用这些“现成的”解决方案!应该比自己处理更好!它们包括有关如何自定义功能的文档和示例。
顺便说一句,我认为 Apple 不建议使用 AlertViews 来让用户对应用程序进行评分。负责任地使用提到的工具。不要太快地提示用户,并确保包含永久关闭按钮!
如果您在这里寻求问题的技术解决方案(即在启动时提示并使用永久关闭按钮),以下是您应该执行的操作的概述:
You seem to be doing an alert to rate your app in the app store, instead of answering your direct (technical) question, I'll try to solve the larger issue. You should consider an existing Open Source solution to handle prompting users for reviews, you can control features like how many launches/days later to prompt them.
I can recommend Appirater by Arash Pyan. What it does is handle the rating portion of the app automatically. It take users right into your App's review page and its very customizable. The best solution for a new developer! It's available on GitHub.
iRate by demosthenese is a similar solution but is cleaner and supports fast app switching.
Use these "off the shelf" solutions instead! It should work out better rather than handle it yourself! They include documentation and samples on how to customize the features.
As an aside, I think Apple doesn't recommend using AlertViews for getting users to rate applications. Use the tools mentioned responsibly. Don't prompt users too quickly, and make sure that you include a dismiss forever button!
If you're here for a technical solution to the issue (ie on Prompt on launch with a dismiss forever button), here's an overview of what you should do:
你会想要使用类似 NSUserDefaults 的东西,也许像这样:
You'll want to use something like the NSUserDefaults, maybe like this:
你可以使用这个功能
you can use this function
首先,添加另一个if语句测试buttonIndex 2。然后,我相信您会想要使用NSUserDefaults类来存储BOOL。然后,如果点击“不,谢谢”按钮,则将此 BOOL 设置为 NO。在 viewdidLoad 方法中测试此 BOOL 的值,仅当 BOOL 为 YES 时才显示警报。
First, add another if statement testing buttonIndex 2. Then, I believe you're going to want to use the NSUserDefaults class to store a BOOL. Then, set this BOOL to NO, if the "No thanks" button is tapped. Test for the value of this BOOL in your viewdidLoad method and display the alert only if the BOOL reads YES.