只见UIAlertController笑,不见UIAlertView哭

今天跟着视频教学准备在问题回答完成后跳出一个UIAlertView提醒答题结束。敲代码时就发现自动提示上带着一道禁止的红色提示。运行时果然报错了。

从iOS8开始,苹果开始用UIAlertController替代UIAlertView,到了iOS9似乎是彻底不能用了。

在谷歌上搜索了UIAlertController的使用方法,将视频中的代码改写如下:

UIAlertController* alert=[UIAlertControlleralertControllerWithTitle:@"Congratulations" message:[NSStringstringWithFormat:@"CorrectAnswer:%d",self.correctCount] preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* reset = [UIAlertAction actionWithTitle:@"Reset" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){

self.index=0;///点击Reset后的动作,回到第一个的猜题界面

intcoin=[self.coinView.currentTitleintValue];

coin=10000;

[self.coinViewsetTitle:[NSStringstringWithFormat:@"%d",coin]forState:UIWindowLevelNormal];

[self viewDidLoad];///网上的例子只要dismiss这个UIAlertController,运行后再点击其他按钮会报错,就改成了viewDidLoad

}];

UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){

self.index--;

[self  nextClick];

}];

[alert  addAction:ok];

[alert  addAction:cancel];

[self  presentViewController:alertanimated:YEScompletion:nil];

详细代码已上传全球最大的同性交友网站,可参考github。网上的例子有7道题,删除了一些侵犯肖像权的只剩了两道。。。

运行截图如下


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容