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