IOS8 UIAlertController prompt box
In IOS8, Apple integrates UIActionSheet and UIAlertView into an interface UIAlertController.
The original view is displayed on the window view. Now it is changed to controller, and the display mode is changed to directly present from the current controller.
- UIAlertController* Alert=[UIAlertControllerAlertControllerWithTitle: @ ThisIsTitle
- Message: @ ThisIsMessage
- PreferredStyle: UIAlertControllerStyleAlErt];
- [AlertAddAction: [UIAlertActionActionWithTitle: @ Action1(DefaultStyle)
- Style: UIAlertActionStyleDefaulT
- Handler: ^ (UIAlertAction* Action){
- NSLog (@ Action1HandlerCalled );
- }];
-
- [AlertAddAction: [UIAlertActionActionWithTitle: @ Action2(CancelStyle)
- Style: UIAlertActionStyleCancel
- Handler: ^ (UIAlertAction* Action){
- NSLog (@ Action2HandlerCalled );
- }];
-
- [AlertAddAction: [UIAlertActionActionWithTitle: @ Action3(DestructiveStyle)
- Style: UIAlertActionStyleDestruCtive
- Handler: ^ (UIAlertAction* Action){
- NSLog (@ Action3HandlerCalled );
- }];
-
- [SelfPresentViewController: alertAnimated: YESCompletion: nil]; add a specific button through the addAction interface, set the button title, style, and add the button response interface directly using the block method.
Style has the following types:
[Objc]
- UIAlertControllerPrompt Box>
- UIAlertControllerPrompt Box>
- Typedef NS_ENUM (NSInteger,UIAlertActionStyle){
- UIAlertActionStyleDefaulT=0,
- UIAlertActionStyleCancel,
- UIAlertActionStyleDestruCtive
- }NS_ENUM_AVAILABLE_IOS (8_0 );
Compared with the original UIActionSheet and UIAlertView:
1. There is no visual change, which is consistent with the previous style;
2. After the controller mode is changed, the lifecycle of the control can be better controlled.
3. After UIAlertController is displayed in the current controller, the present controller must be displayed on the basis of UIAlertController. After present, UIAlertController will be covered. The previous UIActionSheet and UIAlertView are added on the window. When they are present controller on the basis of their controller, the UIActionSheet and UIAlertView bullet boxes are still kept at the top.
4. After the controller mode is changed, the interface is simpler and the button response mode is clearer. You do not need to set delegate and implement response callback.