我试图在一个我从某个网站获取的Pacman游戏中使用这段代码,但是不得不将UIAlertView
更改为UIAlertController
。然而,下面的代码存在两个错误,我不知道如何修复(我是编程新手,感觉这是一个非常初级的问题 - 对不起!!)
第一个错误出现在第4行:alertControllerWithTitle
没有已知的类方法选择器。
第二个错误出现在最后一行:没有可见的接口声明 show
选择器。
- (void)collisionWithExit: (UIAlertController *)alert {
if (CGRectIntersectsRect(self.pacman.frame, self.exit.frame)) {
[self.motionManager stopAccelerometerUpdates];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Congratulations"
message:@"You've won the game!"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil
preferredStyle:UIAlertControllerStyleAlert];
[alert show];
}
}
AlertView
在iOS 9中已经被弃用,因此您必须使用带有更多选项的UIAlertController
。 - vaibhav