This article reprinted to http://blog.csdn.net/jinkaiouyang/article/details/35551769
In IOS8, Apple integrates Uiactionsheet and uialertview into one interface Uialertcontroller.
The original is a view, which is displayed on the window view. Now changed to the controller, the display mode becomes by the current controller directly present out.
Here's a look at the specific interface:
[HTML]View Plaincopy
- Uialertcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "This is Title"
- message:@ "This is message"
- Preferredstyle:uialertcontrollerstylealert];
- [Alert Addaction:[uialertaction actionwithtitle:@ "Action 1 (Default Style)"
- Style:uialertactionstyledefault
- handler:^ (Uialertaction *action) {
- NSLog (@ "Action 1 Handler called");
- }]];
- [Alert addaction:[uialertaction actionwithtitle:@ "Action 2 (Cancel Style)"
- Style:uialertactionstylecancel
- handler:^ (Uialertaction *action) {
- NSLog (@ "Action 2 Handler called");
- }]];
- [Alert addaction:[uialertaction actionwithtitle:@ "Action 3 (destructive Style)"
- Style:uialertactionstyledestructive
- handler:^ (Uialertaction *action) {
- NSLog (@ "Action 3 Handler called");
- }]];
- [Self Presentviewcontroller:alert animated:yes completion:nil];
[HTML]View Plaincopy < param name= "wmode" value= "Transparent" >
- <span style="font-family:arial, Helvetica, Sans-serif;" > When generating Uialertcontroller, you can specify a title, a message, or Preferredstyle to specify whether it is alert or </span> <span style="Color:rgb (61, 29, 129); Font-family:menlo; font-size:14px; " >actionsheet</span>
[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
- typedef ns_enum (Nsinteger, Uialertcontrollerstyle) {
- Uialertcontrollerstyleactionsheet = 0,
- Uialertcontrollerstylealert
- } ns_enum_available_ios (8_0);
Add specific buttons via the Addaction interface, set the button title, style, and join the button response interface directly using block mode.
Style has the following types:
[OBJC]View Plaincopy < param name= "wmode" value= "Transparent" >
- typedef ns_enum (Nsinteger, Uialertactionstyle) {
- Uialertactionstyledefault = 0,
- Uialertactionstylecancel,
- Uialertactionstyledestructive
- } ns_enum_available_ios (8_0);
Compared to the original Uiactionsheet and Uialertview:
1, there is no visual change, with the previous style of consistency;
2, change the controller mode, the control life cycle can be better controlled; Easy eject and pick up
3, the current controller POPs Uialertcontroller, again present controller must present on the basis of Uialertcontroller. After the present, the Uialertcontroller will be covered. And the previous uiactionsheet and Uialertview because it is add on the window, when the controller on the basis of the pop-up present controller, The Uiactionsheet and Uialertview bullets remain at the top of the box.
4, modified to controller mode, the interface is more simple, and the button response more concise introduction, do not need to set delegate and implement response callback and so on.
IOS8 Uialertcontroller Bullet Box