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

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

问题描述

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

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?

推荐答案

我认为这并不难.

在视图控制器中,您有一个 UITextField 和一个 UITableView.将视图控制器指定为两个控件的委托,以及表的数据源.

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.

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

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天全站免登陆