【发布时间】:2015-12-17 20:24:06
【问题描述】:
我尝试了几种方法来使用 UIAlertController,而不是 UIAlertView。我尝试了几种方法,但无法使警报操作起作用。 这是我的代码,在 IOS 8 和 IOS 9 中运行良好,但出现了不推荐使用的标志。我尝试了下面的优雅建议,但我无法使其在这种情况下发挥作用。我需要提交我的应用程序,这是最后要解决的问题。感谢您提供任何进一步的建议。我是新手。
#pragma mark - BUTTONS ================================
- (IBAction)showModesAction:(id)sender {
NSLog(@"iapMade: %d", iapMade3);
// IAP MADE ! ===========================================
if (!iapMade3) {
//start game here
gamePlaysCount++;
[[NSUserDefaults standardUserDefaults]setInteger:gamePlaysCount forKey:@"gamePlaysCount"];
NSLog(@"playsCount: %ld", (long)gamePlaysCount);
if (gamePlaysCount >= 4) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Basic"
message: THREE_PLAYS_LIMIT_MESSAGE
delegate:self
cancelButtonTitle:@"Yes, please"
otherButtonTitles:@"No, thanks", nil];
[alert show];
NSString *path = [[NSBundle mainBundle] pathForResource:@"cow" ofType:@"wav"];
_pop =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[_pop play];
[self dismissViewControllerAnimated:true completion:nil];
} else {
if (gamePlaysCount == 1) {
// Create & store the next 5 mins when player gets 3 more lives
nextDateToPlay = [[NSDate date] dateByAddingTimeInterval:60*60*0.1];
NSLog(@"CURRENT DATE: %@", [NSDate date]);
NSLog(@"NEXT DAY: %@", nextDateToPlay);
[[NSUserDefaults standardUserDefaults]setObject: nextDateToPlay forKey:@"nextDateToPlay"];
NSLog(@"nextDateToPlay: %@", nextDateToPlay);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Basic"
message: THREE_PLAYS_LIMIT_MESSAGE2
delegate:self
cancelButtonTitle:@"Got it!"
otherButtonTitles:@"Start", nil];
[alert show];
} else {
if (gamePlaysCount == 3) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Basic"
message: THREE_PLAYS_LIMIT_MESSAGE3
delegate:self
cancelButtonTitle:@"Yep, I Know!"
otherButtonTitles:@"Start", nil];
[alert show];
}
}
}
}
}
// IAP NOT MADE =============================
#pragma mark - ALERTVIEW DELEGATE ============================
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString:@"Yes, please"]) {
UIStoryboard *storyboard = self.storyboard;
MenuViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"Store"];
svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:svc animated:YES completion:nil];
}
}
【问题讨论】:
-
问题不清楚。你想要什么?
-
UIAlertView 在 IOS 9 中已被弃用,我们必须使用 UIAlertController 来代替 UIAlertControllerStyleAlert 的首选样式。但是,当我使用 UIAlertController 方法时,警报不会显示。我尝试了下面的解决方案,但仍然没有显示警报视图..谢谢..
-
好的。你能证明你做了什么,但没有用吗?
-
展示后你正在调用 [self dismissViewControllerAnimated:true completion:nil];这将关闭警报控制器
-
这是一个重要的问题,因为 UIAlertController 还很新,许多开发人员会担心它会被弃用。不合理的否决票会对有效问题产生不良影响。那些对问题投反对票的人应该在编辑后改变他们的投票。但是,那些因投反对票而获得徽章的“投反对票巨魔”无论如何都不会这样做。 SO 版主应该有办法解决它。
标签: ios objective-c uialertview uialertcontroller