Swift alert view with OK and Cancel: which button tapped?

前端 未结 6 776
耶瑟儿~
耶瑟儿~ 2021-01-30 01:16

I have an alert view in Xcode written in Swift and I\'d like to determine which button the user selected (it is a confirmation dialog) to do nothing or to execute something.

6条回答
  •  孤街浪徒
    2021-01-30 01:42

    You may want to consider using SCLAlertView, alternative for UIAlertView or UIAlertController.

    UIAlertController only works on iOS 8.x or above, SCLAlertView is a good option to support older version.

    github to see the details

    example:

    let alertView = SCLAlertView()
    alertView.addButton("First Button", target:self, selector:Selector("firstButton"))
    alertView.addButton("Second Button") {
        print("Second button tapped")
    }
    alertView.showSuccess("Button View", subTitle: "This alert view has buttons")
    

提交回复
热议问题