I know how to disable them with .isUserInteractionEnabled but I don't know how to enable them again with func textFieldShouldReturn.
Could you show how and where you do it ?
Is your problem that in textFieldShouldReturn you do not reference the textField you need ?
If so, the simplest is to create IBOutlets for the different textField
Code Block @IBOutlet var text1 : UITextField! |
@IBOutlet var text2 : UITextField! |
@IBOutlet var text2 : UITextField! |
Then in textFieldShouldReturn
Code Block if textField == textField1 { |
textField2.isUserInteractionEnabled = true |
textField3.isUserInteractionEnabled = true |
} |
You can also do it without creating the Outlets, by searching for the textFields.
To be sure you address the correct ones, you could set their tags as 1, 2, 3…
Define the extension:
Code Block extension UIView { |
|
class func getAllSubviews<T: UIView>(from parentView: UIView) -> [T] { |
return parentView.subviews.flatMap { subView -> [T] in |
var result = getAllSubviews(from: subView) as [T] |
if let view = subView as? T { result.append(view) } |
return result |
} |
} |
|
func get<T: UIView>(all type: T.Type) -> [T] { return UIView.getAllSubviews(from: self) as [T] } |
} |
And do this in shouldReturn
Code Block let allTextFields = simpleView.get(all: UITextField.self) |
for aTextField in allTextFields { |
if aTextField != textField && aTextField.tag >= 1 && aTextField.tag <= 3 { // Be sure to address only the ones you want and not the one called in shouldReturn |
aTextField.isUserInteractionEnabled = true |
} |
} |
} |