2011-07-11 35 views
1

我在编程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

你似乎在做一个警报为您的应用中应用商店,而不是回答你的直接(技术)问题,我会尽力解决更大的问题。您应该考虑现有的开放源代码解决方案来处理提示用户的评论,您可以控制功能,例如后几天启动以提示他们。我想推荐Appirater by Arash Pyan。它所做的是自动处理应用的评分部分。它让用户直接进入您应用的评论页面,并且可以自定义。为新开发者提供最佳解决方案!它在GitHub上可用。

iRate demosthenese是一个类似的解决方案,但更清洁,支持快速的应用程序切换。

改为使用这些“现成的”解决方案!它应该更好地工作,而不是自己处理它!它们包括有关如何自定义功能的文档和示例。

顺便说一句,我认为苹果不推荐使用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 


} 


} 
+0

didnt知道愤怒和Appirater。他们肯定看起来更优化的替代品谢谢。 – vascogaspar

2

首先,添加另一个if语句测试buttonIndex 2.然后,我相信你会想用类NSUserDefaults的存储一个BOOL。然后,如果点击“No thanks”按钮,则将此BOOL设置为NO。在您的viewdidLoad方法中测试此BOOL的值,并仅在BOOL读取YES时才显示警报。

+0

你可以提供示例代码?对于n00bish对不起......(: – vascogaspar

3

您可以使用此功能

-(void)dismiss{ 
    [self performSelector:@selector(dismissAlertView:)withObject:alertView afterDelay:2]; 
} 

-(void)dismissAlertView:(UIAlertView *)alertView{ 
    [alertView dismissWithClickedButtonIndex:0 animated:YES]; 
} 
+0

似乎并不工作... – vascogaspar

+0

检查编辑的代码现在 –

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"]; 
    } 
} 
+0

谢谢你工作得很好obrigado;!) – vascogaspar