只見UIAlertController笑,不見UIAlertView哭

今天跟著視頻教學準備在問題回答完成后跳出一個UIAlertView提醒答題結(jié)束。敲代碼時就發(fā)現(xiàn)自動提示上帶著一道禁止的紅色提示。運行時果然報錯了。

從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];///網(wǎng)上的例子只要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];

詳細代碼已上傳全球最大的同性交友網(wǎng)站,可參考github。網(wǎng)上的例子有7道題,刪除了一些侵犯肖像權(quán)的只剩了兩道。。。

運行截圖如下


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容