iOS基本控件之UIAlertController

??????? 在IOS8以后我們就可以用這個(gè)UIAlertController了,本人感覺用慣了UIAlertView,還真的有點(diǎn)不習(xí)慣這個(gè)UIAlertController,所以自己用警告框的時(shí)候基本用的都還是UIAlertView,可是在IOS9之后這個(gè)UIAlertView就要被放棄了,昨天IOS10剛出來,那我現(xiàn)在就得把項(xiàng)目中自己用到的這個(gè)UIAlertView修改成這個(gè)controller了,今天在用的時(shí)候,我發(fā)現(xiàn)給這個(gè)controller添加事件的時(shí)候取消永遠(yuǎn)是在前邊,這看著會(huì)不會(huì)太奇葩了,UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//do sure action

}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

//do cancel action

}];

[alertController addAction:sureAction];

[alertController addAction:cancelAction];

這樣的話,取消在前邊,如下圖:

好吧 奇葩,所以我想著是不是這個(gè)cancel有問題,所以我這么寫:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"輸入數(shù)值不符合規(guī)則,請(qǐng)重新輸入"? preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//do sure action

}];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//do cancel action

}];

[alertController addAction:sureAction];

[alertController addAction:cancelAction];

[self.viewController presentViewController:alertController animated:YES completion:^{

}];

還真是,解決了問題:

對(duì)于這個(gè)alertController還有一點(diǎn),之前沒注意過,就是直接在controller中寫幾個(gè)textField,注意是幾個(gè),不是只能寫一個(gè),類似下圖:

以后遇到這種需求,不用自定義了,系統(tǒng)都封號(hào)了,當(dāng)然了,如果跟你的需求差別大的話還是需要自己封裝的。alertView也有,不過只能最多有兩個(gè),由于以后不再用alertView,故在此不再贅述。

以后得用這個(gè)AlertController,就像我之前寫的關(guān)于App Store 的IPV6的事中的一句話,真是蘋果打了哈欠,我們就感覺地動(dòng)山搖啊。不關(guān)注蘋果動(dòng)向,隨時(shí)的API可能就不能用了。

Hope To Help You !

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

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

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