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