How do IOS 8 and later build Uialertview?

Source: Internet
Author: User
Tags deprecated

1.

Important: Uialertview is deprecated in IOS 8. (Note that uialertviewdelegate is also deprecated.) To create and manage alerts in IOS 8 and later, instead use Uialertcontroller with a preferredstyle of  C10>uialertcontrollerstylealert.

Uialertview and uialertviewdelegate (proxies are given block callbacks, simpler) are deprecated in iOS8 and later versions, instead using style as Uialertcontrollerstylealert 's uialertcontroller to replace.

2.

In apps this run in versions of iOS prior to iOS 8 with the Uialertview class to display a alert message to the U Ser. An alert view functions similar to but differs in appearance from a action sheet (an instance of Uiactionsheet).

IOS8 Previous versions of Uialertview and Uiactionsheet have similar functionality, but are generated by different classes. Overtones, iOS8 later versions, Uialertview and Uiactionsheet two alert pages will be generated by Uialertcontroller.

3.

How do I create a uialertview version of IOS 8 earlier?  

Objective-c

-(Instancetype) Initwithtitle: (nsstring *)title
Message: (nsstring *)message
Delegate: (ID)delegate
Cancelbuttontitle: (nsstring *)Cancelbuttontitle
Otherbuttontitles: (nsstring *)otherbuttontitles,
...

4.

How do IOS 8 and later build Uialertview?

    1. uialertcontroller* alert = [Uialertcontroller alertcontrollerwithtitle:@ "My alert"
    2. message:@ "This was an alert." Preferredstyle:uialertcontrollerstylealert];
    3. uialertaction* DefaultAction = [uialertaction actionwithtitle:@ "OK" Style:uialertactionstyledefault handler:^ ( Uialertaction * action) {}];
    4. [Alert addaction:defaultaction];
    5. [Self Presentviewcontroller:alert animated:yes completion:nil];

5.

How do I create a uiactionsheet version of IOS 8 earlier?

-(Instancetype) Initwithtitle: (nsstring *)title

Delegate: (id<uiactionsheetdelegate>)delegate

Cancelbuttontitle: (nsstring *)cancelbuttontitle

Destructivebuttontitle: (nsstring *)destructivebuttontitle

Otherbuttontitles: (nsstring *)otherbuttontitles

...

6.

How do IOS 8 and later build Uiactionsheet?

Uialertcontroller *ALERTVC = [Uialertcontroller alertcontrollerwithtitle:@ "Cang teacher Hello" message:@ "I heard your new movie was downloaded 9,999 times" Preferredstyle:uialertcontrollerstylealert];

Uialertaction *action1 = [uialertaction actionwithtitle:@ "OK" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {

Self.lblTarget.text = [NSString stringwithformat:@ "Click the alertview OK button to generate a random number"];

Self.lblTarget.textColor = [Uicolor Redcolor];

}]; Click the button after the block callback to execute this method, so no need to use the agent

Uialertaction *action2 = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ (UIAlertAction * _nonnull action) {

}]; /*uialertactionstylecancel blue font, bold;

Uialertactionstyledefault font blue, not bold;

uialertactionstyledestructive font red, not bold;

*/

[ALERTVC Addaction:action1];

[ALERTVC Addaction:action2];

[Self PRESENTVIEWCONTROLLER:ALERTVC animated:yes completion:nil];

How do IOS 8 and later build Uialertview?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.