Swift UI Learning Uialertcontroller (getting into trouble)

Source: Internet
Author: User

Uialertview is used in the code, because there is no intelligent hint, the compilation is not a problem, but when triggered, it crashes, and there is no

Any hint, do not know what is wrong, if you encounter the same situation, we know how to solve.

An extension is written here, which makes it easier to use

[OBJC]  View plain  copy  print? import foundation   import uikit      Extension uialertcontroller  {       class func showalert (            presentController: UIViewController!,            title: String!,           message:  String!,           cancelbuttontitle: string?  =  "Cancel",           okbuttontitle: string?  =  "OK")  {           let alert =  uialertcontroller (title: title!, message: message!, preferredstyle:  Uialertcontrollerstyle.alert)            if cancelbuttontitle {                Alert.addaction (Uialertaction (Title: cancelbuttontitle!, style: uialertactionstyle.default,  handler: nil))// do not handle cancel, just dismiss            }           if  okButtonTitle {                Alert.addaction (Uialertaction (title: okbuttontitle!, style: uialertactionstyle.default,  Handler: nil))// do not handle cancel, just dismiss            }                      presentcontroller!. Presentviewcontroller (alert, animated: true,  completion: nil)        }              class func showalert (            presentController: UIViewController!,            title: string!,           message: String!,            cancelButtonTitle: String? =  "Cancel",            okButtonTitle: String? =  "OK",            okHandler:  ((uialertaction!)  -> void)!)  {               let alert  = uialertcontroller (title: title!, message: message!, preferredstyle:  UialertcontrollersTyle. Alert)                if  cancelbuttontitle {                    alert.addaction (Uialertaction (title: cancelbuttontitle!, style:  Uialertactionstyle.default, handler: nil))// do not handle cancel, just  dismiss               }               if okButtonTitle {                     Alert.addaction (Uialertaction (title: okbuttontitle!, style: uialertactionstyle.default,  Handler: okhandler))// do not handle cancel, just dismiss                }                               presentcontroller!. Presentviewcontroller (alert, animated: 

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.