在我的应用程序中,我在后台进行了一些搜索(NSOperationQueue),一旦完成并在主队列的UITableView中显示结果,但UIKeyboardType总是被重置。
如果用户更改了当前的UIKeyboardType,我该怎么办?
我尝试在搜索之前将类型存储在变量中,但是正在进行搜索的textField没有返回可见的键盘的实际类型,而是返回默认情况下设置为的UIKeyboardType。
答案 0 :(得分:1)
以下是我为解决问题所做的工作。我检查了他们输入搜索字段的最后一个字符是什么,并根据它确定了UIKeyboardType:
if ([searchText length]>0) {
NSRange nond = [[searchText substringFromIndex:[searchText length]-1] rangeOfCharacterFromSet:[[NSCharacterSet lowercaseLetterCharacterSet] invertedSet]];
if (NSNotFound == nond.location) {
self.currentKeyboardType = UIKeyboardTypeDefault;
} else {
self.currentKeyboardType = UIKeyboardTypeNumberPad;
}
}
然后在搜索完成后,我将UIKeyboardType设置为此值。在我看来,默认情况下,我的应用程序是根据我为UISearchBar文本字段设置的默认键盘将键盘切换回来的。这对我很有用。
答案 1 :(得分:0)
您可以使用textField.keyboardType
并获取textField的键盘类型...