Recent Apple update IOS8 has made great changes to the past, the updated API is also very urgent, it is said that one of the new features of iOS 8 is to make the interface more adaptable and flexible, so many views of the implementation of the controller has changed dramatically. The new Uipresentationcontroller, for example, plays an important role in achieving transition animations between view controllers and adaptive device size changes, such as rotation, which effectively saves the programmer's workload. But at the same time some of the old Uikit controls also changed a lot, and many of the controls that were customized on the old control had a strange bug, in fact Uialertview, Uiactionsheet (and their respective delegate protocols) in IOS 8 has been deprecated, press and hold the click Uialertview or Uiactionsheet in your code and you'll see the top note: Uialertview is deprecated. Use Uialertcontroller with a preferredstyle of Uialertcontrollerstylealert instead. Although the class has been deprecated, in @availability Property does not express this. Uialertview is still available at the moment. Update is not scary, learned can be used. This article will give a general introduction to the changes in alert views and action sheets.
Uialertview
With Apple's last release of iOS 5, Uialertview is full of bottom-line concessions, sacrificing format and design correctness to meet developers ' preferences. Uialertview warning box has been widely used, easy to use, the application is huge, general use time often accompanied by two keys, OK & Cancel. For example:
Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "title" message:@ "This is the default style for Uialertview" delegate:self cancelbuttontitle:@ "Cancel" otherbuttontitles:@ "good", nil]; [Alertview show];
You can also implement the effect of entering text, passwords, and even login boxes by changing the Alertviewstyle property of the Uialertview. The Uialertviewdelegate protocol has a callback method that responds to the button action of the dialog view. And when the text box content changes, call the Alertviewshouldenableotherbutton: method to make the button dynamically available or unavailable.
It is useless to say so much, because after IOS8.0, Apple has not advised us to use Uialertview, but the new Uialertcontroller
Uialertcontroller
Uialertcontroller also replaces Uialertview and Uiactionsheet, unifying the concept of alert at the system level-either in modal or PopOver mode.
Uialertcontroller is a subclass of Uiviewcontroller, not its previous way. So the new alert can benefit a lot from the view controller's presentation of the relevant configuration.
Uialertcontroller is initialized with the title and message parameters, whether it is to be displayed in alert or action sheet mode. Alert appears in modal form in the currently displayed view Controller center, and action sheet slides out at the bottom. Alert can have both a button and an input box, and action sheet only supports buttons.
The new approach does not put all the alert button configurations in the initialization function, but introduces a new class Uialertaction object that can be configured after initialization. This form of API refactoring allows for greater control over the number, type, and order of buttons. It also discards the delegate used by Uialertview and Uiactionsheet, but uses a simpler callback when it's done.
<span style= "color: #33cc00;" ><strong>//Note here the </strong></span><span style= "font-family: ' Helvetica Neue ', Helvetica, Stheiti, Microsoft Jas Black, Blackbody, Arial, Tahoma, Sans-serif, serif; ><span style= "color: #33cc00;" The ><strong>preferredstyle parameter is an enumeration value <span style= "Color:rgb (51, 204, 0); font-family:menlo;font-size:18px; line-height:28px; White-space:pre; ">uialertcontrollerstyleactionsheet is the original uiactionsheet</span></strong></span></span> <p style= "margin-top:0px; margin-bottom:0px; Font-family:menlo; " ></p><p style= "margin-top:0px; margin-bottom:0px; Font-family:menlo; " ><span style= "color: #33cc00;" >typedef Ns_enum (Nsinteger, Uialertcontrollerstyle) {</span></p><p style= "margin-top:0px; margin-bottom:0px; Font-family:menlo; " ><span style= "color: #33cc00;" > Uialertcontrollerstyleactionsheet = 0,</span></p><p style= "margin-top:0px; margin-bottom:0px; Font-family:menlo; " ><span style= "color: #33cc00;" > uialertcontrollerstylealert</span></p><p style= "margin-top:0px; margin-bottom:0px; Font-family:menlo; " ><span style= "color: #33cc00;" } ns_enum_available_ios (8_0);</span></p>
<pre name= "code" class= "OBJC" ><span style= "color: #33cc00;" ><strong>//Note that the style parameter here is the button style, and the enumeration value is:</strong></span>, respectively.
</pre><pre name= "code" class= "OBJC" style= "Color:rgb (255, 102, 0);" >uialertaction *cancelaction = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil]; Uialertaction *sureaction = [uialertaction actionwithtitle:@ "OK" style:uialertactionstyledefault Handler:nil]; [Alertcontroller addaction:cancelaction]; [Alertcontroller addaction:sureaction];
Not finished, because now the warning box has been "evolved" from a view as a controller, so the display is no longer a show or showin, but
[Self PresentViewController:self.alertController animated:yes completion:nil];
Note that the test must not be placed in the
-(void) viewdidload
method, (hint) can be written in the view to appear or customize a button trigger method.
Viewdidload
Viewdidload
iOS Development IOS8.0 Latest Uialertcontroller