uitextfielddelegate

Format UITextField text without having cursor move to the end

人走茶凉 提交于 2019-12-02 16:38:57
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 … Receive and display text change immediately (same issue applies when I return false and do the text replacement manually) func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool { let range:NSRange = NSRange(location: range.location, length: range.length) let newString =

regex in swift is not working with this example?

 ̄綄美尐妖づ 提交于 2019-12-02 16:09:12
问题 I am trying to use Regex expressions but this does not work and I don't understand why. The println is not showing up in the output. I followed this tutorial to use this class : class Regex { let internalExpression: NSRegularExpression let pattern: String init(_ pattern: String) { self.pattern = pattern var error: NSError? self.internalExpression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error) } func test(input: String) -> Bool { let matches = self

How to pass data back to ViewController holding Container View and TableViewController that is embedded in the Container? Swift 3

﹥>﹥吖頭↗ 提交于 2019-12-02 14:23:08
How can I call func checkField when nextButton is tapped? If no field is empty in ManagedTableEleventhViewController, I'd like to segue to TwelvethViewController. I have a UIViewController ElevethViewController which holds a container view. The container view has an embed segue to a UITableViewController ManagedTableEleventhViewController . From ElevethViewController there is a Show segue to a UIViewController TwelevethViewController The View hierarchy looks like this: ElevethViewController Container View ManagedTableEleventhViewController embedded in Container View with Embed segue Show segue

Swift format text field when user is typing

六眼飞鱼酱① 提交于 2019-12-02 14:13:33
问题 I'm trying to format an expiry field so that it formats the text as follows: MM / YY I can get the textfield to add in the extra characters when the user is typing however when I come to delete the numbers the code will not allow you to go passed two characters before adding in the " / " again. Is there a way I can recognise when the user is deleting and bypass the text field check? ExpiryOutlet.addTarget(self, action: #selector(ExpiryDidChange(_:)), for: .editingChanged) func ExpiryDidChange

Bug? UILabel live updating by UITextFieldDelegate is off by one character

风流意气都作罢 提交于 2019-12-02 10:39:13
问题 Here is a sample app to demonstrate the issue that I ran into: import UIKit class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var aTextField: UITextField! @IBOutlet weak var aTextLbl: UILabel! override func viewDidLoad() { super.viewDidLoad() aTextField.delegate = self } func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { aTextLbl.text = aTextField.text return true } } Here is a demo: Link to

Weird error while using UITextFieldDelegate

我与影子孤独终老i 提交于 2019-12-02 09:41:22
I have this error while messing with UITextField delegate: Can't find keyplane that supports type 8 for keyboard Wildcat-Landscape-QWERTY-Pad; using 3673479387_Wildcat-Alphabetic-Keyboard_Capital-Letters Someone have any idea what is it? Thanks in advance. for iPad you can't use keyboard type: Decimal Pad ; you must change it to Number and Punctuation , etc 来源: https://stackoverflow.com/questions/16486312/weird-error-while-using-uitextfielddelegate

regex in swift is not working with this example?

て烟熏妆下的殇ゞ 提交于 2019-12-02 08:38:08
I am trying to use Regex expressions but this does not work and I don't understand why. The println is not showing up in the output. I followed this tutorial to use this class : class Regex { let internalExpression: NSRegularExpression let pattern: String init(_ pattern: String) { self.pattern = pattern var error: NSError? self.internalExpression = NSRegularExpression(pattern: pattern, options: .CaseInsensitive, error: &error) } func test(input: String) -> Bool { let matches = self.internalExpression.matchesInString(input, options: nil, range:NSMakeRange(0, countElements(input))) return

Custom UITextField delegate set to self initiates infinite loop

戏子无情 提交于 2019-12-02 06:17:30
问题 I am writing iPhone App in which I need custom UITextField class. For my text fields I need indent, image inside before the text and max characters. For this reason I created custom class based on UITextField. All my text fields will be based on this new class. I use Google and searched Stackoverflow and I find that in cases like mine I have to use self.delegate = self; during the init so I don't need to implement methods like textFieldShouldBeginEditing or textFieldShouldEndEditing inside my

Swift format text field when user is typing

落爺英雄遲暮 提交于 2019-12-02 03:33:49
I'm trying to format an expiry field so that it formats the text as follows: MM / YY I can get the textfield to add in the extra characters when the user is typing however when I come to delete the numbers the code will not allow you to go passed two characters before adding in the " / " again. Is there a way I can recognise when the user is deleting and bypass the text field check? ExpiryOutlet.addTarget(self, action: #selector(ExpiryDidChange(_:)), for: .editingChanged) func ExpiryDidChange(_ textField: UITextField) { if textField == ExpiryOutlet { if textField.text != "" && textField.text?

Design Approach for Subclassing UITextField with default behaviors in delegate methods

亡梦爱人 提交于 2019-12-02 02:34:47
问题 I have subclassed the UITextField class so I can provide some built-in functionality for my application. I've changed the appearance to provide only an underline border for the UX design. Also, I want to use this control in situations where there is a picker (pick list, date / time picker). In these cases, I want to prevent editing BUT I still need to respond to touch events. To do this, I've added inspectable properties to control it from IB. I can easily prevent the copy/paste menu from