1

I am posting here because i can't find a solution to a very strange problem actually. On every single text field in my app, every time I try to focus on a text field, the view print the view of my main view in my app, which is managed with a navigation controller and a Reveal View Controller (SWRevealViewController framework).

Here are a few pics to show you.

Without focus: Without focus

With focus: With focus

I tried to change the FirstResponder but it did not work, here is my code from a container view in my app which contains a few textFields :

func textFieldShouldReturn(textField: UITextField) -> Bool {
    self.view.endEditing(true)
    textField.resignFirstResponder()
    if (textField == self.cityField) {
        self.cityField.becomeFirstResponder()
    }
    else if (textField == self.streetField) {
        self.streetField.becomeFirstResponder()

    }
    else if (textField == self.countryField) {
        self.countryField.becomeFirstResponder()
    }
    else if (textField == self.postalCodeField) {
        self.postalCodeField.becomeFirstResponder()
    }

    return false
}

Can anyone help me?

Dave Batton
  • 8,795
  • 1
  • 46
  • 50
meteorSD
  • 339
  • 3
  • 16

2 Answers2

0

You don't need these lines:

self.view.endEditing(true)
textField.resignFirstResponder()

Also, you're telling the current first responder to become the first responder. That doesn't make sense. This is what I'd expect to see (assuming the order of the fields in the view matches the order in your code):

func textFieldShouldReturn(textField: UITextField) -> Bool {
    if (textField == self.cityField) {
        self.streetField.becomeFirstResponder()
    }
    else if (textField == self.streetField) {
        self.countryField.becomeFirstResponder()
    }
    else if (textField == self.countryField) {
        self.postalCodeField.becomeFirstResponder()
    }
    else if (textField == self.postalCodeField) {
        self.view.endEditing(false)
    }

    return false
}
Dave Batton
  • 8,795
  • 1
  • 46
  • 50
  • That did not work for me (i paid attention to the order), I forgot to mention that this textFieldShouldReturn function is from a container view where the textFields belongs. Anyway every single textField in my app has this problem. – meteorSD Feb 15 '16 at 10:38
0

I finally found my problem : I had two windows in the same app. It took me a long time to figure it out. Here is where I found the solution : In iOS7 Text Magnifier isn't working app wide

Community
  • 1
  • 1
meteorSD
  • 339
  • 3
  • 16