??????? 在IOS8以后我們就可以用這個UIAlertController了仔涩,本人感覺用慣了UIAlertView,還真的有點(diǎn)不習(xí)慣這個UIAlertController,所以自己用警告框的時候基本用的都還是UIAlertView锤躁,可是在IOS9之后這個UIAlertView就要被放棄了黍翎,昨天IOS10剛出來,那我現(xiàn)在就得把項目中自己用到的這個UIAlertView修改成這個controller了腻要,今天在用的時候复罐,我發(fā)現(xiàn)給這個controller添加事件的時候取消永遠(yuǎn)是在前邊,這看著會不會太奇葩了雄家,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];
這樣的話效诅,取消在前邊,如下圖:
好吧 奇葩咳短,所以我想著是不是這個cancel有問題填帽,所以我這么寫:
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"警告" message:@"輸入數(shù)值不符合規(guī)則,請重新輸入"? 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:^{
}];
還真是咙好,解決了問題:
對于這個alertController還有一點(diǎn)篡腌,之前沒注意過,就是直接在controller中寫幾個textField勾效,注意是幾個嘹悼,不是只能寫一個,類似下圖:
以后遇到這種需求层宫,不用自定義了杨伙,系統(tǒng)都封號了,當(dāng)然了萌腿,如果跟你的需求差別大的話還是需要自己封裝的限匣。alertView也有,不過只能最多有兩個毁菱,由于以后不再用alertView米死,故在此不再贅述。
以后得用這個AlertController,就像我之前寫的關(guān)于App Store 的IPV6的事中的一句話贮庞,真是蘋果打了哈欠峦筒,我們就感覺地動山搖啊。不關(guān)注蘋果動向窗慎,隨時的API可能就不能用了物喷。
Hope To Help You !