get the current UIKeyBoardType that is being used? Or capture when the UIKeyboardType has changed

StackOverflow https://stackoverflow.com/questions/15006074

Domanda

In my app I do some searching in the background (NSOperationQueue) and once I am done and show the results in a UITableView on the main queue but the UIKeyboardType always gets reset.

How can I get the current UIKeyboardType once it is changed by the user?

i tried storing the type in a variable before the search but the textField that is doing the search is not returning the actual type of keyboard that is visible but rather the UIKeyboardType that is set to by default.

È stato utile?

Soluzione

Here is what I did to solve my problem. I checked to see what the last character was they typed in to the search field and determined the UIKeyboardType based on that:

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;
        }
    }

Then after the search completes I set the UIKeyboardType to this value. It seems to me that by default my app was switching the keyboard back based on the default keyboard I had set for the UISearchBar text field. This is working great for me.

Altri suggerimenti

You can use textField.keyboardType and get the type of keyboard for a textField...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top