为什么对于UITextField,-UIKeyInput hasText总是返回NO?这是UIKit的bug吗?
例如,以下测试失败:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectZero];
textField.text = @"has text";
STAssertTrue([textField hasText], @"any text is text.");发布于 2011-12-12 02:18:40
UITextField通过UITextInput协议实施UIKeyInput,该协议规定:
UIKeyInput协议-实现以获取插入点的文本输入和删除功能。
(通过:http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UITextInput_Protocol/Reference/Reference.html)
正如Mattias上面所建议的,它与后备存储器有更多的关系,并且主要用于通过系统键盘输入。
在您的示例中,您将直接操作该属性并绕过通过键盘的输入。通过给字段first responder,键盘将被显示,hasText将如预期地返回YES。
https://stackoverflow.com/questions/8465789
复制相似问题