美文网首页
最新版本IQKeyboardManager第三方库中"

最新版本IQKeyboardManager第三方库中"

作者: iOS开发小学生 | 来源:发表于2017-11-26 23:18 被阅读923次

这是老版本的第三方IQKeyboardManager 写法

-(void)doneAction:(IQBarButtonItem*)barButton

{

//If user wants to play input Click sound. Then Play Input Click Sound.

if (_shouldPlayInputClicks)

{

[[UIDevice currentDevice] playInputClick];

}

UIView *textFieldRetain = _textFieldView;

BOOL isResignedFirstResponder = [self resignFirstResponder];

if (isResignedFirstResponder == YES &&

textFieldRetain.doneInvocation)

{

[textFieldRetain.doneInvocation invoke];

}

//发送通知

if (textFieldRetain.tag==50001) {

[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"doneAction" object:nil userInfo:nil]];

}

}

这是最新的版本写法

-(void)doneAction:(IQBarButtonItem*)barButton

{

//If user wants to play input Click sound. Then Play Input Click Sound.

if (_shouldPlayInputClicks)

{

[[UIDevice currentDevice] playInputClick];

}

UIView *currentTextFieldView = _textFieldView;

BOOL isResignedFirstResponder = [self resignFirstResponder];

if (isResignedFirstResponder == YES && barButton.invocation)

{

if (barButton.invocation.methodSignature.numberOfArguments > 2)

{

[barButton.invocation setArgument:¤tTextFieldView atIndex:2];

}

[barButton.invocation invoke];

}

  UIView *textFieldRetain = _textFieldView;

   BOOL isResignedFirstResponder = [self resignFirstResponder];

   if (isResignedFirstResponder == YES && textFieldRetain.doneInvocation)  {      [textFieldRetain.doneInvocation invoke];

    }

}

}

大家仔细看会发现新的版本把监听方法去掉了,所以造成监听失效

那解决办法是

-(void)doneAction:(IQBarButtonItem*)barButton

{

//If user wants to play input Click sound. Then Play Input Click Sound.

if (_shouldPlayInputClicks)

{

[[UIDevice currentDevice] playInputClick];

}

UIView *currentTextFieldView = _textFieldView;

BOOL isResignedFirstResponder = [self resignFirstResponder];

if (isResignedFirstResponder == YES && barButton.invocation)

{

if (barButton.invocation.methodSignature.numberOfArguments > 2)

{

[barButton.invocation setArgument:¤tTextFieldView atIndex:2];

}

[barButton.invocation invoke];

}

//    UIView *textFieldRetain = _textFieldView;

//

//    BOOL isResignedFirstResponder = [self resignFirstResponder];

//

//    if (isResignedFirstResponder == YES &&

//        textFieldRetain.doneInvocation)

//    {

//        [textFieldRetain.doneInvocation invoke];

//    }

//发送通知

if (currentTextFieldView.tag==50001) {

[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"doneAction" object:nil userInfo:nil]];

}

}

相关文章

网友评论

      本文标题:最新版本IQKeyboardManager第三方库中"

      本文链接:https://www.haomeiwen.com/subject/ggnlbxtx.html