Here is a snipet of code from a bigger app. This function (is called when a button is clicked)just evaluates which selection from a picker was chosen and assigns a string to it and also get the input a user typed in a text field
that part works fine and it even assigns the correct string that was selected in the picker
i test this by printing the selected string in the console - so it all works great BUT I then try to print that string after the if/else structure and it only prints a blank
Cant figure out the subjectField prints fine as its going through the if/else - so that logic works... but I try to print after thelogic and it prints just a blank line or carriage return (I had added another print statement after the print (subjectField) and it printed fine with a blank above it.
thought it may be a variable issue tried making globals and then decided to try this asa function which is working but why in the heck id subjectField correct when it iterates through else if but not after.
I am sure i am missing something simple....
@IBAction func sendButtonPressed(_ sender: UIButton) {
determineSelRequest(selectedReq: pickedRequest.selectedRow(inComponent: 0), selectedFlightNumber: enteredFlightNumber.text!)
}
func determineSelRequest(selectedReq: Int, selectedFlightNumber: String) {
var selectedRequest = pickedRequest.selectedRow(inComponent: 0)
if selectedRequest == 0 {
var subjectField = "Fltsum "
print (subjectField)
} else if selectedRequest == 1{
var subjectField = "Crew "
//print (selectedRequest)
} else if selectedRequest == 2{
var subjectField = "EDCT "
//print (subjectField)
} else if selectedRequest == 3 {
var subjectField = "Loads "
//print (subjectField)
} else if selectedRequest == 4 {
var subjectField = "Times "
//print (subjectField)
}
var selectedFlightNumber : String = enteredFlightNumber.text!
// print ("now we just have to send mail")
print (selectedFlightNumber)
print (subjectField)
//sendEmail()
}
want the string that the else/if logic put into subjectField to stay there.... not become blank
Aucun commentaire:
Enregistrer un commentaire