开发者

Use special iPad/iPhone autocomplete dictionary for certain text fields/text views?

How does one use a special iPad/iPhone autocomplete dictionary for certain text fields?

So if in a certain text field someone starts typing in: "diarrrh" in a开发者_JAVA技巧 certain text field I want to suggest an autocomplete of diarrhea because it is one of the few known side effects of a drug.

For a given text field/area how can you supply a small limited iPad/iPhone autocomplete dictionary?


You could implement the UITextViewDelegate method textView:shouldChangeTextInRange:replacementText:, inspect the last word a user has entered (basically go from the cursor position backwards to the next word separating character) and present suggestions with UIMenuController. If you additionally want to use the system's spell checker as a fallback for words that aren't in your dictionary, you could use an instance of UITextChecker (new in iOS 3.2).

If you have a UITextField instead of a UITextView, you have to replace "View" with "Field" in the delegate method's signature.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜