IOS8 UIAlertController prompt box

Source: Internet
Author: User

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.

 

  1. UIAlertController* Alert=[UIAlertControllerAlertControllerWithTitle: @ ThisIsTitle
  2. Message: @ ThisIsMessage
  3. PreferredStyle: UIAlertControllerStyleAlErt];
  4. [AlertAddAction: [UIAlertActionActionWithTitle: @ Action1(DefaultStyle)
  5. Style: UIAlertActionStyleDefaulT
  6. Handler: ^ (UIAlertAction* Action){
  7. NSLog (@ Action1HandlerCalled );
  8. }];
  9. [AlertAddAction: [UIAlertActionActionWithTitle: @ Action2(CancelStyle)
  10. Style: UIAlertActionStyleCancel
  11. Handler: ^ (UIAlertAction* Action){
  12. NSLog (@ Action2HandlerCalled );
  13. }];
  14. [AlertAddAction: [UIAlertActionActionWithTitle: @ Action3(DestructiveStyle)
  15. Style: UIAlertActionStyleDestruCtive
  16. Handler: ^ (UIAlertAction* Action){
  17. NSLog (@ Action3HandlerCalled );
  18. }];
  19. [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]
  20. UIAlertControllerPrompt Box>
  21. UIAlertControllerPrompt Box>
    1. Typedef NS_ENUM (NSInteger,UIAlertActionStyle){
    2. UIAlertActionStyleDefaulT=0,
    3. UIAlertActionStyleCancel,
    4. UIAlertActionStyleDestruCtive
    5. }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.

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.