Questions tagged [uitextfielddelegate]

The methods declared by the UITextFieldDelegate protocol allow the adopting delegate to respond to messages from the UITextField class.

The methods declared by the UITextFieldDelegate protocol allow the adopting delegate to respond to messages from the UITextField class. On UITextFieldDelegate, you can find the following methods:

Managing Editing

– textFieldShouldBeginEditing:

– textFieldDidBeginEditing:

– textFieldShouldEndEditing:

– textFieldDidEndEditing:

Editing the Text Field’s Text

– textField:shouldChangeCharactersInRange:replacementString:

– textFieldShouldClear:

– textFieldShouldReturn:

574 questions
635
votes
22 answers

UITextField text change event

How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly. Since until it returns YES, the textField texts are not available to other observer…
karim
  • 15,408
  • 7
  • 58
  • 96
95
votes
10 answers

How shouldChangeCharactersInRange works in Swift?

I'm using shouldChangeCharactersInRange as a way of using on-the-fly type search. However I'm having a problem, shouldChangeCharactersInRange gets called before the text field actually updates: In Objective C, I solved this using using…
Fudgey
  • 3,793
  • 7
  • 32
  • 53
75
votes
17 answers

Switching between Text fields on pressing return key in Swift

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 questions, with excellent answers around but they all just happen to be in…
lucas rodriguez
  • 980
  • 2
  • 8
  • 20
59
votes
4 answers

Cannot assign a value of type ViewController to a value of type UITextFieldDelegate?

Here's the error when I wrote the line self.MessageTextField.delegate = self: /ChatApp/ViewController.swift:27:42: Cannot assign a value of type 'ViewController' to a value of type 'UITextFieldDelegate?' Here's my Swift code…
David
  • 1,660
  • 3
  • 21
  • 33
59
votes
13 answers

Detect backspace Event in UITextField

I am searching for solutions on how to capture a backspace event, most Stack Overflow answers are in Objective-C but I need on Swift language. First I have set delegate for the UITextField and set it to self self.textField.delegate = self; Then I…
Want Query
  • 1,396
  • 1
  • 11
  • 12
40
votes
10 answers

How to detect delete key on an UITextField in iOS 8?

I have subclassed UITextField and implemented the UIKeyInput protocol's deleteBackward method to detect backspace being pressed. This works fine on iOS 7 but not on iOS 8. deleteBackward is not called on the UITextField anymore when I press the…
VNVN
  • 501
  • 1
  • 4
  • 7
36
votes
6 answers

Format UITextField text without having cursor move to the end

I am trying to apply NSAttributedString styles to a UITextField after processing a new text entry, keystroke by keystroke. The problem is that any time I replace the text the cursor will jump the very end on each change. Here's my current approach…
Bernd
  • 11,133
  • 11
  • 65
  • 98
31
votes
4 answers

Next/Done button using Swift with textFieldShouldReturn

I have a MainView that adds a subview (signUpWindow) when a sign up button is pressed. In my signUpWindow subview (SignUpWindowView.swift), I set up each field with a function, as an example: func confirmPasswordText() { …
Amy Plant
  • 656
  • 1
  • 7
  • 16
29
votes
7 answers

Allow only alphanumeric characters for a UITextField

How would I go about allowing inputting only alphanumeric characters in an iOS UITextField?
WalterF
  • 1,345
  • 2
  • 11
  • 26
29
votes
6 answers

Swift how to resign first responder on all uiTextfield

I would like to use resign the first responder on all uitextfield. I'm able to complete this by placing the uitextfields in an array but I wanted to avoid using the array. the resign should happen to all type of uiTextField how can this be…
SwiftER
  • 1,235
  • 4
  • 17
  • 40
26
votes
7 answers

UITextField lose focus event

I have an UITextField in a MyCustomUIView class and when the UITextField loses focus, I'd like to hide the field and show something else in place. The delegate for the UITextField is set to MyCustomUIView via IB and I also have 'Did End On Exit' and…
Alexi Groove
  • 6,646
  • 12
  • 47
  • 54
22
votes
3 answers

UITextField delegate methods are not fired when setting text programmatically

I've created a custom input view for entering text into UITextField. Basically it's just custom designed number pad. I have textfields, on which I've set the inputView property to use my custom created UIView subclass. In that view I have collection…
kyurkchyan
  • 2,260
  • 2
  • 23
  • 37
22
votes
1 answer

iOS Swift Pass Closure as Property?

Let's say I have a custom UIView, lets call it MyCustomView. Inside this view is a UITextField property. Suppose my goal is to be able to create an instance of MyCustomView and add it to some view controller somewhere, and I want that view…
Mike
  • 9,765
  • 5
  • 34
  • 59
22
votes
7 answers

Detecting a change to text in UITextfield

I would like to be able to detect if some text is changed in a UITextField so that I can then enable a UIButton to save the changes.
RGriffiths
  • 5,722
  • 18
  • 72
  • 120
21
votes
7 answers

How to detect when user used Password AutoFill on a UITextField

I've implemented all the app and server changes necessary to support Password Autofill on iOS 11, and it works well. I'd like it to work a little better. My username and password fields are UITextFields. I would like to identify when a user has…
Mitch Cohen
  • 1,551
  • 3
  • 15
  • 29
1
2 3
38 39