1

I would like to process the value in the textfield of alert controller after users tap an AlertAction (such as a "send button" maybe) on the alert controller without making it dismiss.

I knew that the built-in UIAlertController from Apple would naturally dismiss after users tap any button on the alert controller. So I chose SDCAlertView (from CocoaPods), which does not dismiss after users' tapping button. However, I got some problem.

I made an alert controller using SDCAlertView by the following code:

let alert = AlertController(title: "Title", message: "This is a message")
alert.addAction(AlertAction(title: "Dismiss", style: .Default)) // the button do dismiss
alert.addTextFieldWithConfigurationHandler()

// the button that DO NOT dismiss
let sendAction = AlertAction(title: "Send", style: .Default, handler: { (sendAction) in

    // The following functions in the closure are not called after sendAction is tapped
    print("(alert.textFields![0].text)")
    // and further process to alert.textFields![0].text
    print("Send")
})

alert.addAction(sendAction)
alert.shouldDismissHandler = { $0!.title == "Dismiss" }
alert.present()

I would like to process the value in the textfield after the sendAction button was taped. However, the functions are not called. Is it possible to fix this problem?

Thank you!

0 Answers0