uitextfielddelegate

swift 2.0 - UITextFieldDelegate protocol extension not working

痴心易碎 提交于 2019-11-28 18:47:28
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 textFieldShouldReturn(textField: UITextField) -> Bool { // textField.resignFirstResponder() // return true // } } extension UITextFieldDelegate { func textFieldShouldReturn(textField: UITextField) -> Bool { textField.resignFirstResponder() return true } } As you may guess, the keyboard never dismiss. I can't really see where's the problem here. Is this a

textField:shouldChangeCharactersInRange:replacementString:

我们两清 提交于 2019-11-28 11:28:00
问题 How can I correct this code. I want only numbers and range should be not exceed to 10. My code is - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSUInteger newLength = [textField.text length] + [string length] - range.length; return (newLength > 10) ? NO : YES; static NSCharacterSet *charSet = nil; if(!charSet) { charSet = [[[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet] retain]; }

Detect backspace Event in UITextField

橙三吉。 提交于 2019-11-28 04:32:41
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 know to use shouldChangeCharactersInRange delegate method to detect if a backspace was pressed is all code are in Objective-C. I need in Swift these following method as below is used. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { const char * _char = [string

How to detect when user used Password AutoFill on a UITextField

自作多情 提交于 2019-11-28 00:12:12
问题 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 "autofilled" one of the two UITextFields, so I can progress to the next step. Currently the user autofills an item, then needs to press the "Next" button on the on-screen keyboard in order to advance. I'd like to trigger this on behalf of the user. The

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

此生再无相见时 提交于 2019-11-27 13:23:42
问题 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 (ViewerController.swift): // // ViewController.swift // ChatApp // // Created by David Chen on 15/4/12. // Copyright (c) 2015年 cwsoft. All rights reserved. // import UIKit import Parse class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

Properly Subclassing UITextField in swift

余生颓废 提交于 2019-11-27 11:44:34
问题 So i have these textfields that i realised that they all have same properties, so i created new class called " UserInputs " and extended from UITextField , everything works properly except one thing, UITextFieldDelegate functions doesn't work, i mean when i focus on them it doesn't work, i want to add it in code because when you focus on my input fields they change border, how do i properly subclass from UITextField the only problems that i have are that functions: textFieldDidBeginEditing

swift 2.0 - UITextFieldDelegate protocol extension not working

∥☆過路亽.° 提交于 2019-11-27 11:39:33
问题 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 textFieldShouldReturn(textField: UITextField) -> Bool { // textField.resignFirstResponder() // return true // } } extension UITextFieldDelegate { func textFieldShouldReturn(textField: UITextField) -> Bool { textField.resignFirstResponder() return true } } As

How shouldChangeCharactersInRange works in Swift?

此生再无相见时 提交于 2019-11-27 09:56:29
问题 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 below: -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string]; return YES; } However, I've

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

本小妞迷上赌 提交于 2019-11-27 03:34:25
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 backspace key. I've checked the documentation and the release notes and nothing points to the reason why this could happen. Any pointers? iVader You must look an example for MBContactPicker on github. Deletion of contacts at MBContactPicker via Backspace button on iOS8 tested by me. And it works greatly! You can use its as example. Author of

Detect backspace Event in UITextField

試著忘記壹切 提交于 2019-11-27 00:22:06
问题 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 know to use shouldChangeCharactersInRange delegate method to detect if a backspace was pressed is all code are in Objective-C. I need in Swift these following method as below is used. -(BOOL)textField:(UITextField *)textField