Code Monkey home page Code Monkey logo

inputkit's Issues

LimitedTextField.swift 不设置delegate 不能正常使用

Version: InputKit.swift-1.1.10
目前使用的是Swift3.x
在 Swfit3.x 版本的 InputKit-1.1.10 release 版本的 SwfitDemo里面,如果不设置

textField.delegate = self

的话,无法进行输入限制,OC版是可以不设置delegate的

兼容textFieldDidEndEditing

根据苹果API注释

- (void)textFieldDidEndEditing:(UITextField *)textField reason:(UITextFieldDidEndEditingReason)reason NS_AVAILABLE_IOS(10_0); 
// if implemented, called in place of textFieldDidEndEditing:

建议作以下修改,这样才能遵循苹果原来的代理调用顺序,否则真正代理只实现了textFieldDidEndEditing的时候并不能被调用。

- (void)textFieldDidEndEditing:(UITextField *)textField reason:(UITextFieldDidEndEditingReason)reason NS_AVAILABLE_IOS(10_0) {
    id realDelegate = self.realDelegate;
    if (realDelegate) {
        if ([realDelegate respondsToSelector:@selector(textFieldDidEndEditing:reason:)])
            [realDelegate textFieldDidEndEditing:textField reason:reason];
        else if ([realDelegate respondsToSelector:@selector(textFieldDidEndEditing:)])
            [realDelegate textFieldDidEndEditing:textField];
    }
}

使用作者在readme中的例子,只允许中文输入,结果输入不了任何字符

  • (void)viewDidLoad {
    [super viewDidLoad];

    TXLimitedTextField *textField = [[TXLimitedTextField alloc] initWithFrame:CGRectMake(20, 200, 100, 30)];
    textField.backgroundColor = [UIColor blueColor];
    // Of course, you can custom your field
    textField.limitedType = TXLimitedTextFieldTypeCustom;

    // you can also set the property in this type. It limits the max number of characters that you input
    textField.limitedNumber = 10;

    // limitedRegExs is a type of array argument that you can via it, and pass your regular expression to TXLimitedTextField. kTXLimitedTextFieldChineseOnlyRegex is a constant that define in TXMatchConst.h file. it's represent that only Chinese characters can be inputted.
    textField.limitedRegExs = @[kTXLimitedTextFieldChineseOnlyRegex];

    [self.view addSubview:textField];

    // Do any additional setup after loading the view, typically from a nib.
    }

Does not archive after update to swift4.1 and latest xcode and sdk

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:226:33: value of optional type '((UITextView) -> Bool)?' not unwrapped; did you mean to use '!' or '?'?

flag = realDelegate.textViewShouldEndEditing(textView)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:234:26: value of optional type '((UITextView) -> Void)?' not unwrapped; did you mean to use '!' or '?'?

realDelegate.textViewDidBeginEditing(textView)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:241:26: value of optional type '((UITextView) -> Void)?' not unwrapped; did you mean to use '!' or '?'?

realDelegate.textViewDidEndEditing(textView)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:250:33: value of optional type '((UITextView, NSRange, String) -> Bool)?' (aka 'Optional<(UITextView, _NSRange, String) -> Bool>') not unwrapped; did you mean to use '!' or '?'?

flag = realDelegate.textView(textView, shouldChangeTextIn: range, replacementText: text)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:285:26: value of optional type '((UITextView) -> Void)?' not unwrapped; did you mean to use '!' or '?'?

realDelegate.textViewDidChange(textView)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:292:26: value of optional type '((UITextView) -> Void)?' not unwrapped; did you mean to use '!' or '?'?

realDelegate.textViewDidChangeSelection(textView)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:300:33: value of optional type '((UITextView, URL, NSRange, UITextItemInteraction) -> Bool)?' (aka 'Optional<(UITextView, URL, _NSRange, UITextItemInteraction) -> Bool>') not unwrapped; did you mean to use '!' or '?'?

flag = realDelegate.textView(textView, shouldInteractWith: URL, in: characterRange, interaction: interaction)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:310:33: value of optional type '((UITextView, NSTextAttachment, NSRange, UITextItemInteraction) -> Bool)?' (aka 'Optional<(UITextView, NSTextAttachment, _NSRange, UITextItemInteraction) -> Bool>') not unwrapped; did you mean to use '!' or '?'?

flag = realDelegate.textView(textView, shouldInteractWith: textAttachment, in: characterRange, interaction: interaction)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:319:33: value of optional type '((UITextView, URL, NSRange) -> Bool)?' (aka 'Optional<(UITextView, URL, _NSRange) -> Bool>') not unwrapped; did you mean to use '!' or '?'?

flag = realDelegate.textView(textView, shouldInteractWith: URL, in: characterRange)
^

❌ /Users/sergeypetrachkov/Money.Cashier.iOS/src/Pods/InputKitSwift/InputKitSwift/LimitedTextView.swift:328:33: value of optional type '((UITextView, NSTextAttachment, NSRange) -> Bool)?' (aka 'Optional<(UITextView, NSTextAttachment, _NSRange) -> Bool>') not unwrapped; did you mean to use '!' or '?'?

etc

正则限制,输入中文报错

image
image

2017-06-28 16:55:36.990 InputKitDemo_OC[22341:244100] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString replaceOccurrencesOfString:withString:options:range:]: Range {9, 10} out of bounds; string length 10'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000108052d4b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x0000000107ab421e objc_exception_throw + 48
	2   CoreFoundation                      0x00000001080bc2b5 +[NSException raise:format:] + 197
	3   CoreFoundation                      0x0000000107fb8e93 -[__NSCFString replaceOccurrencesOfString:withString:options:range:] + 531
	4   Foundation                          0x00000001075992a0 -[NSString stringByReplacingOccurrencesOfString:withString:options:range:] + 184
	5   InputKitDemo_OC                     0x00000001074c1da1 -[TXLimitedTextField textFieldTextDidChangeNotification:] + 1649
	6   CoreFoundation                      0x0000000107ff05ec __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
	7   CoreFoundation                      0x0000000107ff04eb _CFXRegistrationPost + 427
	8   CoreFoundation                      0x0000000107ff0252 ___CFXNotificationPost_block_invoke + 50
	9   CoreFoundation                      0x0000000107fb3282 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
	10  CoreFoundation                      0x0000000107fb231b _CFXNotificationPost + 667
	11  Foundation                          0x000000010757a81b -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
	12  UIKit                               0x0000000108f976d4 -[UITextField fieldEditorDidChange:] + 257
	13  UIKit                               0x0000000108fa5a53 -[UITextInputController _sendDelegateChangeNotificationsForText:selection:] + 120
	14  UIKit                               0x0000000108f9b7a5 -[UITextField unmarkText] + 48
	15  UIKit                               0x0000000108a8aa51 -[UIResponder(UITextInput_Internal) _unmarkText] + 61
	16  UIKit                               0x000000010873f8dd -[UIKeyboardImpl unmarkText] + 43
	17  UIKit                               0x000000010873f9df -[UIKeyboardImpl unmarkText:] + 180
	18  UIKit                               0x0000000108742a6d __59-[UIKeyboardImpl handleAcceptedCandidate:executionContext:]_block_invoke_2 + 180
	19  UIKit                               0x0000000108fc736b -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 385
	20  UIKit                               0x0000000108fc7e70 -[UIKeyboardTaskQueue waitUntilTaskIsFinished:] + 261
	21  UIKit                               0x0000000108fc7fd3 -[UIKeyboardTaskQueue performSingleTask:] + 268
	22  UIKit                               0x000000010874b869 -[UIKeyboardImpl acceptCurrentCandidateForInput:] + 249
	23  UIKit                               0x0000000108b7bca2 -[UIKeyboardCandidateBar collectionView:didSelectItemAtIndexPath:] + 246
	24  UIKit                               0x0000000108daf6e4 -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 702
	25  UIKit                               0x0000000108dda4d2 -[UICollectionView touchesEnded:withEvent:] + 649
	26  UIKit                               0x000000010868df6b forwardTouchMethod + 348
	27  UIKit                               0x000000010868e034 -[UIResponder touchesEnded:withEvent:] + 49
	28  UIKit                               0x000000010868df6b forwardTouchMethod + 348
	29  UIKit                               0x000000010868e034 -[UIResponder touchesEnded:withEvent:] + 49
	30  UIKit                               0x00000001084e6545 -[UIWindow _sendTouchesForEvent:] + 2747
	31  UIKit                               0x00000001084e7c33 -[UIWindow sendEvent:] + 4011
	32  UIKit                               0x00000001084949ab -[UIApplication sendEvent:] + 371
	33  UIKit                               0x0000000108c8172d __dispatchPreprocessedEventFromEventQueue + 3248
	34  UIKit                               0x0000000108c7a463 __handleEventQueue + 4879
	35  CoreFoundation                      0x0000000107ff7761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	36  CoreFoundation                      0x0000000107fdc98c __CFRunLoopDoSources0 + 556
	37  CoreFoundation                      0x0000000107fdbe76 __CFRunLoopRun + 918
	38  CoreFoundation                      0x0000000107fdb884 CFRunLoopRunSpecific + 420
	39  GraphicsServices                    0x000000010be44a6f GSEventRunModal + 161
	40  UIKit                               0x0000000108476c68 UIApplicationMain + 159
	41  InputKitDemo_OC                     0x00000001074c713f main + 111
	42  libdyld.dylib                       0x000000010aeb468d start + 1
	43  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

身份证正则 问题

let kLimitedTextCarIDRegex = "(^[0-9]{15}$)|([0-9]{17}([0-9]|X)$)"
textField.limitedRegEx = MatchConstant.Name.kLimitedTextCarIDRegex
textField.limitedType = .custom
输入框什么都不能输入,这种情况应该咋用啊?

Simultaneous accesses

Thread 1: Simultaneous accesses to 0x7ff41c812b18, but modification requires exclusive access

set {
limitedDelegate = LimitedTextViewDelegate(realDelegate: newValue)
super.delegate = limitedDelegate
}

Typo in LimitedTextField.swift breaks control behavior

Return button on keyboard does not work because we check for wrong selector textFieldShouldClear in textFieldShouldReturn

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        var flag = true
        if let realDelegate = self.realDelegate, realDelegate.responds(to: #selector(textFieldShouldClear(_:))) {
            flag = realDelegate.textFieldShouldClear(textField)
        }
        return flag
    }

真正的代理里把text=nil出问题

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;

假如在真正的代理里执行以上方法时把textView.text=nil,再执行以下方法进行匹配就会出错

    BOOL flag = YES;
    id realDelegate = self.realDelegate;
    if (realDelegate && [realDelegate respondsToSelector:@selector(textView:shouldChangeTextInRange:replacementText:)])
        flag = [realDelegate textView:textView shouldChangeTextInRange:range replacementText:text];
    
    int matchResult = YES;
    
    if ([textView isKindOfClass:[TXLimitedTextView class]]) {
        TXLimitedTextView *limitedTextView = (TXLimitedTextView *)textView;
        
        NSMutableString *matchStr = [NSMutableString stringWithString:textView.text];

所以不管TXLimitedTextView还是TXLimitedTextField,在匹配正则时应该判断.text是否为空。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.