为iPhone创建组合框 [英] Creating a combo box for the iPhone

查看:132
本文介绍了为iPhone创建组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于没有用于创建通过Safari在网页上看到的组合框(或选择框)的预先存在的组件,有人可以提供一个示例或预先存在的创建一个第三方组件吗?

解决方案

我不认为这很难做。



一个UITextField和一个UITableView。



实现UITextField委托方法 textField:shouldChangeCharactersInRange :replacementString:。这将截取在您在文本字段中输入的更改。在此方法中,遍历可能的选项列表,并将匹配存储在视图控制器上的NSMutableArray实例变量中。然后调用 [myTableView reloadData]



从您之前存储的匹配数组生成表格单元格。 / p>

这应该相当简单,除了几个委托方法之外,不应该花费太多代码。


Since there is no pre-existing component for creating a combobox (or select box) as seen on webpages through Safari, can someone provide an example or pre-existing 3rd party component of creating one?

解决方案

I don't think this is hard to do.

In a view controller you have a UITextField and a UITableView. Assign the view controller to be the delegate of the both controls, plus the data source of the table.

Implement the UITextField delegate method textField:shouldChangeCharactersInRange:replacementString: in your controller. This intercepts the changes as they are being typed in your text field. In this method, iterate through your list of possible options and store the matches in an NSMutableArray instance variable on your view controller. Then call [myTableView reloadData].

Have your table cells generated from the array of matches you previously stored.

It should be pretty straightforward and shouldn't take much code at all beyond a few delegate methods to get working.

这篇关于为iPhone创建组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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