2016-07-22 8 views
2

ich finde void return alert aber string alert return nicht gefunden. Void zu String versuchtswift code return alert type String funktioniert nicht

// return Void Alert 
func returnAlert(title: String!, message: String! ,success: (() -> Void)? , cancel: (() -> Void)?) { 
    dispatch_async(dispatch_get_main_queue(), { 
     let alertController = UIAlertController(title:title, 
      message: "", 
      preferredStyle: UIAlertControllerStyle.Alert) 

     self.newQtyField = UITextField() 
     self.newQtyField.keyboardType = .NumberPad 

     func addTextField(textField: UITextField!){ 
      // add the text field and make the result global 
      let row = self.array[Int(message)!] 
      textField.text = String(row.pbQty!) 
      self.newQtyField = textField 
     } 


     let cancelLocalized = NSLocalizedString("cancel", tableName: "activity", comment:"") 
     let okLocalized = NSLocalizedString("ok", tableName: "Localizable", comment:"") 

     let cancelAction: UIAlertAction = UIAlertAction(title: cancelLocalized, 
     style: .Cancel) { 
      action -> Void in cancel?() 
     } 
     let successAction: UIAlertAction = UIAlertAction(title: okLocalized, 
     style: .Default) { 
      action -> Void in success?() 
     } 
     alertController.addTextFieldWithConfigurationHandler(addTextField) 
     alertController.addAction(cancelAction) 
     alertController.addAction(successAction) 


     self.presentViewController(alertController, animated: true, completion: nil) 
    }) 
} 

// unten Anruf fun | Ich denke, Erfolg: {() zum Erfolg: {Textfeld, aber nicht funktioniert, wie ... Ihre Hilfe benötigt

returnAlert("title", message: "msg", success: {() -> Void in 


     }) 
    {() -> Void in 
     print("user canceled") 
    } 
+0

Haben Sie den Text 'newQtyField' zurückkehren wollen, wenn Benutzer berühren "OK"? – t4nhpt

+0

ja ist es !!! es ist wie du sagst. –

Antwort

0

Sehr schwer zu verstehen, was Sie in Ihrer Frage sagen.

Sie sollten die Methodendefinition dies ändern:

func returnAlert(title: String!, message: String! ,success: ((text:String) -> Void)? , cancel: (() -> Void)?) { 

und die successAction ändern Sie den Wert des UITextField zurückzukehren:

let successAction: UIAlertAction = UIAlertAction(title: okLocalized, 
      style: .Default) { action in 
       success?(text: self.newQtyField.text!) 
      } 
+0

Danke! Ich vervollständige den Code –

Verwandte Themen