UIAlertController 包含 ?UIAlertView 和 UIActionSheet
1.UIActionSheet
UIActionSheet*sheet = [[UIActionSheetalloc]initWithTitle:@"你要做啥"delegate:nilcancelButtonTitle:@"是"destructiveButtonTitle:@"不是" otherButtonTitles:@"關閉",nil];
[sheet showInView:self.view];
展示在底部
2.UIAlertView
UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"message:@"確定關閉么"delegate:nilcancelButtonTitle:@"是"otherButtonTitles:@"不是",nil];
alert.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;
[alert show];
展示在中間
2.UIAlertController
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"message:@"完成"preferredStyle:UIAlertControllerStyleAlert];
[selfpresentViewController:alertanimated:YEScompletion:nil]; ?
展示在中間
添加 關閉 或者 取消 的按鈕事件 通過(UIAlertAction)
[alert addAction[UIAlertAction actionWithTitle:@"確定"style:UIAlertActionStyleDestructive handler:^(UIAlertAction*action) {? NSLog(@"點擊了確定按鈕"); }]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction*action) { ?NSLog(@"點擊了取消按鈕"); ?}]];
添加文本框
[alert addTextFieldWithConfiguration Handler:^(UITextField*textField) { textField.textColor= [UIColor blueColor];
textField.text=@"";
[textField addTarget:selfaction:@selector(usernameDidChange:)forControlEvents:UIControlEventEditingChanged];
}];
延伸:模態(tài)視圖?
模態(tài)視圖:從屏幕下方滑出來,完成的時候需要關閉這個模態(tài)視圖,如果不關閉兔院,就不能做別的事情颓屑,必須有響應處理的含義过蹂。主視圖控制器---》模態(tài)視圖控制器冷尉。主視圖控制器與模態(tài)視圖控制器之間為父子關系豁跑。
UIViewController類中殿怜,主要有以下兩個方法:
presentViewController:animated:completion 呈現(xiàn)模態(tài)視圖
dismissViewControllerAnimated:completion 關閉模態(tài)視圖