對於大多數的App來講,彈框這種交互方式基本上是必不可少的。在新的iOS系統中(具體版本我忘了),之前的UIAlertView被棄用,而換成了如今的UIAlertController。學習
UIAliterController的使用方式與以前的UIAlterView的區別仍是比較大的,剛開始用可能須要學習一下。典型的使用方法以下:spa
1 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"郵箱格式不正確" message:@"請正確輸入郵箱地址" preferredStyle:UIAlertControllerStyleAlert]; 2 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"肯定" style:UIAlertActionStyleDefault handler:nil]; 3 [alert addAction:okAction]; 4 [self presentViewController:alert animated:YES completion:nil];
一共分爲4步:code
1.實例化一個UIAlertController,而且賦以標題和內容以及Alert的Styleblog
2.實例化一個Action,並賦以Action的標題、Style以及Action的Handler blockit
3.將actoin賦給 第1步定義的AlertControllerio
4.顯示AlterController,而且定義Alert消失後的操做的blockclass