-4

I have alert, that write to iOS 8+, I must write same alert to the iOS 7.0 (I'm use four alert's with other request)

There are my code:

    func AlertForNumber () {
    var alertController: UIAlertController?
    //
    alertController = UIAlertController(title: "First", message: "Enter number", preferredStyle: .Alert)
    alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
        textField.text = "38"
    })
    let action = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {[weak self]
        (paramAction: UIAlertAction!) in
        if let textFields = alertController?.textFields {
            let textFields = textFields as! [UITextField]
            let enterText = textFields[0].text
            if (count(enterText) < 12){
                self?.ErrorForNumber()
            } else {
                self!.data.numberID = enterText
                self!.data.SaveData(enterText, codetext: self!.data.codeID)
                self!.json.UfR()
            }
        }
        })
    alertController?.addAction(action)
    dispatch_async(dispatch_get_main_queue(), {
        self.presentViewController(alertController!, animated: true, completion: nil)

    })
}

At that alert I must input my number, and send to the server. I must use only alert with text field After I must input code at next alert:

func AlertForCode () {
    var alertController: UIAlertController?
    alertController = UIAlertController(title: "Second", message: "Enter code", preferredStyle: .Alert)
    alertController!.addTextFieldWithConfigurationHandler({(textField: UITextField!) in
        textField.placeholder = code_text
    })
    let action = UIAlertAction(title: "Next", style: UIAlertActionStyle.Default, handler: {[weak self]
        (paramAction: UIAlertAction!) in
        if let textFields = alertController?.textFields {
            let textFields = textFields as! [UITextField]
            let enterText = textFields[0].text
            self!.data.codeID = enterText
            self!.data.SaveData(self!.data.numberID, codetext: enterText)
            self!.json.UfR()
        }
        })
    alertController?.addAction(action)
    dispatch_async(dispatch_get_main_queue(), {
        self.presentViewController(alertController!, animated: true, completion: nil)
    })

}

So that I must write to the iOS 7.0

  • 4
    possible duplicate of [how to get input from UIAlertView?](http://stackoverflow.com/questions/882915/how-to-get-input-from-uialertview) – sage444 Aug 14 '15 at 09:33
  • just first answer from google http://stackoverflow.com/a/9962890/1403732 – sage444 Aug 14 '15 at 09:33

1 Answers1

0
func AlertForNumber () {
    let alertView = UIAlertView(title: "First", message: "Enter number", delegate: self, cancelButtonTitle: "Next")
    alertView.alertViewStyle = UIAlertViewStyle.PlainTextInput
    alertView.textFieldAtIndex(0)?.text = "38"
    alertView.show()
}

func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
    println("next")
    let enterText = alertView.textFieldAtIndex(0)!.text
    if (count(enterText) < 12){
        self?.ErrorForNumber()
    } else {
        self!.data.numberID = enterText
        self!.data.SaveData(enterText, codetext: self!.data.codeID)
        self!.json.UfR()
    }
}
Glauco Neves
  • 3,483
  • 1
  • 24
  • 36