UITextField自动完成? [英] UITextField Autocomplete?

查看:74
本文介绍了UITextField自动完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出是否有一种方法可以在UITextField中实现特定值的自动完成功能.

I am trying to figure out if there is a way to implement an autocomplete functionality in a UITextField for specific values.

我知道UITextField可以使用iPhone词典来做到这一点(就像在safari中搜索google等),但是我希望能够以编程方式使其正确地适应我指定的某些值.

I know that the UITextField can do this using the iPhone dictionary (much like searching google in safari, etc), but I want to be able to programmatically have it correct to certain values that I specify.

该怎么做?

推荐答案

Brett,

当我从事一个最近的相当大的项目时,我做了与此非常相似的事情.我们有一个不断变化的自动完成条款列表,并围绕它们建立了一个自动完成.

I did something very similar to this while working on a recent and rather large project. We had a constantly changing list of auto complete terms and built an auto-complete around them.

首先,您需要制作某种类型的自动完成控制器.它应该包含一个字符串,并返回该字符串的所有可能的自动完成条款.

First, you'll want to make some type of auto-complete controller. It should take a string and return all possible auto complete terms for that string.

-(NSArray *)completionsForString:(NSString *)myString;

然后,检查UIMenuController类.该类显示了许多应用程序中的剪切/复制/粘贴选项.您可以获取它的共享实例,自己填充菜单项,并将其显示在文本字段上方.然后,用户只需轻按他们想要的术语即可.

Then, check out the UIMenuController class. It's the class that shows the cut/copy/paste options in many applications. You can get the shared instance of it, populate the menu items yourself, and show it above the text field. The user can then simply tap the term they want.

最后,该解决方案确实可以很好地满足我们的需求.我希望它对您有用.

In the end, the solution worked really well for our needs. I hope it works for you.

这篇关于UITextField自动完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆