彈跳式視窗的用法
在 iOS 裡彈跳式視窗主要分為由下方昇起的 UIActionSheet 以及Dialog 類型的 UIAlertView
iOS8起 UIAlertView 已 deprecated, 改統一使用 UIAlertController
用法範例如下
Simple alert example:
UIAlertController * alert= [UIAlertController alertControllerWithTitle:@"Password required" message:@"Please enter password" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
Alert with ok button example
UIAlertController * alert= [UIAlertController
alertControllerWithTitle:@"Name required"
message:@"Please input name"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* okAction = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:NO completion:nil];
// do something
}];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
ActionSheet example
UIAlertController * view= [UIAlertController
alertControllerWithTitle:@"Select Sex"
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* male = [UIAlertAction
actionWithTitle:@"Male"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:NO completion:nil];
// do something
}];
UIAlertAction* female = [UIAlertAction
actionWithTitle:@"Roaster"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:NO completion:nil];
// do something
}];
UIAlertAction* other = [UIAlertAction
actionWithTitle:@"Individual"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:NO completion:nil];
// do something
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];
}];
[view addAction:male];
[view addAction:female];
[view addAction:other];
[view addAction:cancel];
[self presentViewController:view animated:YES completion:nil];
Thanks for sharing excellent informations. Your web site is so cool. I am impressed by the details that you’ve on this blog. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. Wonderful. I found simply the information I already searched everywhere and simply could not come across. What an ideal web site.
regards
Thank you very much for your appreciation.
By the way, I am wondering if you can read Chinese or by google translation?
I was hesitated to either write in English or Chinese but couldn’t figure out.
Anyway, feel free to write me if you have some questions about my blogs.
Regards.