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:

549 questions
598
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
  • 14,810
  • 7
  • 55
  • 92
79
votes
7 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…
Ryan
  • 3,544
  • 7
  • 28
  • 52
69
votes
16 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
  • 900
  • 2
  • 8
  • 16
56
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,589
  • 3
  • 16
  • 31
44
votes
12 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,226
  • 1
  • 11
  • 12
39
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
  • 491
  • 1
  • 4
  • 7
33
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
  • 10,009
  • 11
  • 60
  • 93
28
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
  • 608
  • 1
  • 7
  • 16
24
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,215
  • 1
  • 9
  • 22
24
votes
6 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,526
  • 11
  • 43
  • 54
23
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,125
  • 4
  • 13
  • 38
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,225
  • 5
  • 32
  • 59
21
votes
2 answers

swift 2.0 - UITextFieldDelegate protocol extension not working

I'm trying to add a default behavior on some UITextFieldDelegate's methods using protocol extensions like so : extension ViewController: UITextFieldDelegate { // Works if I uncommented this so I know delegates are properly set // func…
Yaman
  • 3,839
  • 4
  • 34
  • 58
21
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,174
  • 16
  • 63
  • 99
20
votes
2 answers

Action of the "Go" button of the ios keyboard

How do I bind an action to the Go button of the keyboard in iOS ?
Alexis
  • 15,669
  • 15
  • 60
  • 101
1
2 3
36 37