我是编程UIAlertView的新手。我的想法是做一个弹出窗口,除了默认的关闭按钮之外,在启动应用程序时显示另外两个按钮。 其中一个按钮是指向appstore的链接,另一个按钮是永久关闭该弹出窗口。 除了最后一个按钮,我已经完成了所有工作。 有什么帮助吗?
谢谢!
- (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#" ]];
}
}
答案 0 :(得分:3)
你可以使用这个功能
-(void)dismiss{
[self performSelector:@selector(dismissAlertView:)withObject:alertView afterDelay:2];
}
-(void)dismissAlertView:(UIAlertView *)alertView{
[alertView dismissWithClickedButtonIndex:0 animated:YES];
}
答案 1 :(得分:3)
你会想要使用像NSUserDefaults这样的东西,也许是这样的:
- (void)viewDidLoad
{
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"com.mycompany.myapp.block_rate_reminder"])// this could be any string as long as it's descriptive enough for you (and match what you use to set, of course)
{
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#" ]];
}
if (buttonIndex == 2)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"com.mycompany.myapp.block_rate_reminder"];
}
}
答案 2 :(得分:3)
您似乎在为应用程序商店中的应用评分提醒,而不是回答您的直接(技术)问题,我会尝试解决更大的问题。您应该考虑使用现有的开源解决方案来处理提醒用户进行评论,您可以控制一些功能,例如每天启动多少次启动它们。
我可以推荐Appirater by Arash Pyan。它的作用是自动处理应用程序的评级部分。用户可以直接进入App的评论页面,并且可以自定义。新开发人员的最佳解决方案!它可以在GitHub上找到。
demosthenese的iRate是一个类似的解决方案,但更清洁,支持快速应用切换。
使用这些“现成的”解决方案!它应该更好,而不是自己处理它!它们包括有关如何自定义功能的文档和示例。
另外,我认为Apple不建议使用AlertViews来让用户对应用程序进行评级。负责任地使用提到的工具。不要太快提示用户,并确保包含永久关闭按钮!
如果您在这里寻找问题的技术解决方案(例如,在启动提示时使用永久解雇按钮),这里概述了您应该做什么:
-(void)viewdidload{
//Access NSUSerDefaults and check a variable called launch
// launch's default value is 0
if (launch == 0) {
alert = [[UIAlertView alloc] initWithTitle:@"Rate!" message:@"You'll see this everytime you launch until you click Dismiss Forever" delegate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"Okay! ", @"Dismiss Alert and Don't Show it to me", nil ];
[alert show];
[alert release];
}
}
else
{
//nothing
}
//continue customizing
}
-(void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
//Assume this is the Okay Button
{
//Now use NSUserDefaults and set a variable called launch to 1
// the default value for launch should be 0
// now that its set to 1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ILoveAlertViews.com" ]];
}
if (buttonIndex == 1) {
//assume this is the dismiss button
//Now use NSUserDefaults and set a variable called launch to 2
//2 means that they never want to see it. The AlertView should not be called on the next launch
}
}
答案 3 :(得分:2)
首先,添加另一个if语句测试buttonIndex 2.然后,我相信你会想要使用NSUserDefaults类来存储BOOL。然后,如果点击“不,谢谢”按钮,则将此BOOL设置为NO。在viewdidLoad方法中测试此BOOL的值,并仅在BOOL读为YES时显示警报。