Sclalertview-swift: Prevent from close when button is tapped

Created on 16 Dec 2016  路  4Comments  路  Source: vikmeup/SCLAlertView-Swift

when using text field
alert.showEdit("title", subTitle: "This alert view shows a text box")

if text field is empty i don't want to close dialog and show user a message that 'please enter text',
how to prevent from close when dialog button is clicked?

Most helpful comment

Hi, I faced the same problem and I resolved it differently.

You can just set "shouldAutoDismiss" in appearance and then, manually dismiss the alert.
Maybe it will not be helpful for you, but it can be for others ;)

let appearance = SCLAlertView.SCLAppearance( shouldAutoDismiss: false ) let alert = SCLAlertView(appearance: appearance) alert.addButton("Keep open") { // Your code here } alert.addButton("Close") { alert.hideView() } alert.showEdit("Title", subTitle: "subTitle")

All 4 comments

i have modified source code just commit sideview() in buttonTapped(_) method, and manually close dialog by calling hideview or close function

func buttonTapped(_ btn:SCLButton) {
        if btn.actionType == SCLActionType.closure {
            btn.action()
        } else if btn.actionType == SCLActionType.selector {
            let ctrl = UIControl()
            ctrl.sendAction(btn.selector, to:btn.target, for:nil)
        } else {
            print("Unknow action type for button")
        }

        if(self.view.alpha != 0.0 && appearance.shouldAutoDismiss)
        {
        //    hideView()
        }

    }

Hi, I faced the same problem and I resolved it differently.

You can just set "shouldAutoDismiss" in appearance and then, manually dismiss the alert.
Maybe it will not be helpful for you, but it can be for others ;)

let appearance = SCLAlertView.SCLAppearance( shouldAutoDismiss: false ) let alert = SCLAlertView(appearance: appearance) alert.addButton("Keep open") { // Your code here } alert.addButton("Close") { alert.hideView() } alert.showEdit("Title", subTitle: "subTitle")

@YoannLth yes, this helped me! Thanks for sharing 馃槉

What is the Objective C 'equivalent' - that performs this? I don't see AutoDismiss - thx!

let appearance = SCLAlertView.SCLAppearance(
            shouldAutoDismiss: false
)
let alert = SCLAlertView(appearance: appearance)
alert.addButton("Keep open") {
      // Your code here
}
alert.addButton("Close") {
    alert.hideView()
}
alert.showEdit("Title", subTitle: "subTitle")
Was this page helpful?
0 / 5 - 0 ratings

Related issues

p0tvin29 picture p0tvin29  路  3Comments

ewan34500 picture ewan34500  路  3Comments

rayhk6 picture rayhk6  路  29Comments

ossmalpha picture ossmalpha  路  16Comments

galileomd picture galileomd  路  3Comments