Ich habe Mühe, den genauen Wert eines Eureka-Formulars zu extrahieren. Unten ist so weit mein Quellcode:Wie extrahiert man den aus Eureka Forms analysierten Wert?
class CommunityReportViewController: FormViewController, MFMailComposeViewControllerDelegate{
@IBOutlet weak var activityIndicator: UIActivityIndicatorView!
var userTitleChoice: String = ""
var userCategoryChoice : String = ""
var userDescriptionChoice: String = ""
@IBOutlet weak var submitReport: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
form +++ Section("Feedback Type")
<<< SegmentedRow<String>("feedbackType"){
$0.options = ["Comments", "Bug Reports", "Questions"]
$0.value = "Comments"
}.onChange{ row in
let userDefault = NSUserDefaults.standardUserDefaults()
userDefault.setValue(row.value, forKey: "feedbackType")
}
+++ Section("Follow up?")
<<< ActionSheetRow<String>("officeLocation"){
$0.title = "Where are you?"
$0.selectorTitle = "Please select the office you are located in"
$0.options = ["Singapore", "Prague", "New Jersey"]
}
+++ Section("Best time to contact you?")
<<< PopoverSelectorRow<String>("preferredMethod"){
$0.title = "Preferred Method"
$0.options = ["Phone", "Email", "Do Not Contact"]
}
<<< DateRow("preferredDate"){
$0.title = "Preferred date"
}
<<< TimeInlineRow("preferredTime"){
$0.title = "Preferred time"
$0.noValueDisplayText = "-:--"
}
<<< ButtonRow() {
$0.title = "Submit Feedback!"
$0.onCellSelection(self.buttonTapped)
}
}
func buttonTapped(cell: ButtonCellOf<String>, row: ButtonRow) {
let valuesDictionary = form.values(includeHidden:true)
print (valuesDictionary["feedbackType"], "Feedback")
print (valuesDictionary["officeLocation"], "Office")
print (valuesDictionary["preferredTime"], "Time")
print (valuesDictionary["preferredMethod"], "Method")
print (valuesDictionary["preferredDate"], "Date")
}
}
Die valuesDictionary zurückgeführt, wie unten Ergebnis zurückgegeben, wenn keine Eingabe vorgesehen ist:
Optional(Optional("Comments")) Feedback
Optional(nil) Office
Optional(nil) Time
Optional(nil) Method
Optional(nil) Date
Wenn korrekte Eingaben zur Verfügung gestellt werden, wird das folgende Ergebnis zurückgegeben:
Optional(Optional("Comments")) Feedback
Optional(Optional("New Jersey")) Office
Optional(Optional(2016-07-08 10:00:23 +0000)) Time
Optional(Optional("Email")) Method
Optional(Optional(2016-07-11 07:00:16 +0000)) Date
Gibt es eine Möglichkeit, nur die Werte zurückzugeben, die vom Benutzer ausgewählt wurden? Weil die zurückgegebenen Ergebnisse schwer zu analysieren sind. Beispiel möchte ich nur die folgenden Ergebnisse zurück
Comments
New Jersey
Email
2016-07-08 10:00:23 +0000
2016-07-11 07:00:16 +0000