Uialertview and Uiactionsheet compatibility problem solutions in iOS8 extreme versions

Source: Internet
Author: User

This article reprinted to http://www.aichengxu.com/view/35326

Uialertview and Uiactionsheet are discarded in iOS8, and their functions will be replaced entirely by Uialertcontroller:

1.Alert usage

Uialertcontroller *alert = [Uialertcontrolleralertcontrollerwithtitle:@ "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");

}]];

[Alert Addtextfieldwithconfigurationhandler: ^ (Uitextfield *textfield) {

Uitextfield * tf = [[Uitextfield alloc]initwithframe: CGRectMake(0, 0, 80 , (+ )];

}];

[self presentviewcontroller: Alert animated:YES completion:nil];

2,actionsheet usage

Uialertcontroller *alertcontroller = [Uialertcontroller alertcontrollerwithtitle:Nil Message:nilpreferredstyle: Uialertcontrollerstyleactionsheet];

[Alertcontroller addaction: [uialertaction actionwithtitle:@ "111"

Style:Uialertactionstyledefault

handler:^ (uialertaction *action) {

NSLog (@ "111");

}]];

[Alertcontroller addaction: [uialertaction actionwithtitle:@ "222"

Style:uialertactionstylecancel

handler:^ (uialertaction *action) {

NSLog (@ "222");

}]];

[self presentviewcontroller: Alertcontroller animated:YES completion:nil];

Version Judgment statement

#define IOS (version) ([[[[[] [[[] Uidevice Currentdevice] systemversion] intvalue] >= version)? 1:0)

can be judged by adding alertcontroller or Aletview and Actionsheet

3. New problem, when the iOS8 under the judgment, return to iOS7 or IOS6 run Xcode, error-------

Reason: Uialertcontroller only in the framework of iOS8 under this file, iOS7 and the following version is not, but compile the time will be compiled (although the runtime does not walk this part of the code)

WORKAROUND: Compile-time judgment, only compile this section under IOS8SDK

#if __iphone_os_version_max_allowed >= 80000

"Alertcontroller Related Code"

#endif

Rerun the Xcode,ok and it will work.

Uialertview and Uiactionsheet compatibility problem solutions in iOS8 extreme versions

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.