您的位置:首页 > 移动开发 > IOS开发

TITokenField 在 iOS7 下出现的问题: 切换到textView后导致tokens成倍增加

2013-12-06 15:52 567 查看
问题描述在 https://github.com/thermogl/TITokenField/commit/3541c875f127c6e07da7204728b3486b906602d0所述: 1、在 iOS7 下运行示例程序。
2、在textField中输入某些 names 中没有的值,例如"zz"。
3、点击 textView。
4、再次回到 textField。
5、重复3-4。
6、textField 中的 tokens 自动复制为多个。

zxcat 猜测:
在 iOS7 中,UITextView 和 UITextField 发生了变化。在某些项目中,他也发现 iOS7 中它们调用委托方法的次数会比iOS6 更多。例如 UITextView 会多出两个委托方法调用
-textViewDidChange: 和 -textViewDidChangeSelection 。这个问题很可能与此有关。
zxcat 经过调试之后,发现问题出自这里:
0x0009f23a in -[TITokenField addToken:] atPods/TITokenField/TITokenField.m:608 0x0009f0bd in -[TITokenFieldaddTokenWithTitle:representedObject:] at Pods/TITokenField/TITokenField.m:5920x0009ef55 in -[TITokenField addTokenWithTitle:] at Pods/TITokenField/TITokenField.m:5850x0009feac in __28-[TITokenField tokenizeText]_block_invoke atPods/TITokenField/TITokenField.m:685 0x032b405d in __53-[__NSArrayIenumerateObjectsWithOptions:usingBlock:]_block_invoke () 0x032b3f92 in-[__NSArrayI enumerateObjectsWithOptions:usingBlock:] () 0x032310a5 in-[NSArray enumerateObjectsUsingBlock:] () 0x0009fd07 in -[TITokenFieldtokenizeText] at Pods/TITokenField/TITokenField.m:684 0x0009e52a in-[TITokenField didEndEditing] at Pods/TITokenField/TITokenField.m:531
tokenfield 失去焦点时会调用-[TITokenField didEndEditing] ,并在其中执行 addToken 方法。但是 addToken 方法中有一句 [self becomeFirstResponder],导致方法递归调用。

因此解决的办法就很简单了,找到 addToken 方法,查找 if(shouldAdd){,然后注释掉 [self becomeFirstResponder]; 语句。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: