我想我错过了一些明显的东西。我有UIAlertView
来获取应用评论,但我无法让按钮做任何事情。我在UIAlertViewDelegate
中调用了my.h
,我还有一个UIAlertview
,它只是在IBAction btn
上,虽然刚刚取消btn
但效果很好
我试过给alert.tag = 1
但是从来没有任何区别所以我评论了我的第一个UIAlertview
,所以我只有一个警报,仍然没有快乐。我想我错过了一些简单的东西。
我还尝试了alertview.cancelButtonIndex
或alertview.firstOtherButtonIndex
而不是0
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"index 0 ");
}
else if (buttonIndex == 1) {
NSLog(@"index 1 ");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.google.com"]];
NSUserDefaults *rateApp = [NSUserDefaults standardUserDefaults];
NSInteger appLaunch = [ rateApp integerForKey:@"appLaunch"];
appLaunch = 0 ;
[rateApp setInteger: appLaunch forKey:@"appLaunch"];
}
else if (buttonIndex == 2) {
NSLog(@"index 2 ");
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
//rate app appLaunch == 5 || appLaunch ==10
NSUserDefaults *rateApp = [NSUserDefaults standardUserDefaults];
NSInteger appLaunch = [ rateApp integerForKey:@"appLaunch"];
if (appLaunch == 1 ) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Like this app ?" message:@"Why not rate at the app store" delegate:nil cancelButtonTitle:@"No thanks" otherButtonTitles:@"Yes",@"Remind me later", nil];
// alert.tag = 1;
[alert show];
}
感谢您的帮助。
答案 0 :(得分:1)
如果要调用其委托方法,AlertView的delegate
应该是self
而不是nil
。
使用此代码:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Like this app ?"
message:@"Why not rate at the app store"
delegate:self
cancelButtonTitle:@"No thanks"
otherButtonTitles:@"Yes",@"Remind me later", nil];