Switching between Text fields on pressing return key in Swift

前端 未结 15 1508
名媛妹妹
名媛妹妹 2020-12-04 09:25

I\'m designing an iOS app and I want that when the return key is pressed in my iPhone it directs me to the next following text field.

I have found a couple of similar

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 09:51

    Just use becomeFirstResponder() method of UIResponder class in your textFieldShouldReturn method. Every UIView objects are UIResponder's subclasses.

    if self.emaillabel.isEqual(self.anotherTextField)
    {
        self.anotherTextField.becomeFirstResponder()
    }
    

    You can find more information about becomeFirstResponder() method at Apple Doc's in here.

提交回复
热议问题