将UIPickerView与自定义值一起使用 [英] Using a UIPickerView with custom values
问题描述
我使用导航控制器和普通视图。在视图中,我想要一个带有自定义值的UIPickerView。它将具有一列,其中包含约15个值。我希望能够为每个值添加一个动作。
Im using a navigation controller and a normal view. In the view I'd like a UIPickerView with custom values in it. It would have one column with about 15 values in it. And I want the ability to add an action to each value.
有什么方法可以使用Xcode做到这一点吗?我似乎找不到适当的帮助。
Is there any way I can do this using Xcode? I can't seem to find the corrent help.
干杯。
推荐答案
您需要查看 UIPickerViewDelegate 的文档。
为了对每个值执行操作,您将实现 pickerView:didSelectRow:inComponent:并根据选择的行采取不同的操作。
In order to have an action for each value you will implement pickerView:didSelectRow:inComponent: and have a different action based on which row was selected.
对于行的内容,您可以实现 pickerView :titleForRow:forComponent:如果您的内容是简单的文本。
For the contents of the rows you can implement pickerView:titleForRow:forComponent: if your contents are simple text.
如果您要自定义绘制的内容,则可以为每个带有 pickerView:viewForRow:forComponent:reusingView:方法。
If you want custom drawn contents you can provide a custom view for each row with the pickerView:viewForRow:forComponent:reusingView: method.
请参阅iPhone开发人员示例中提供的UICatalog示例。
See the UICatalog example that is available in the iPhone Developer examples.
这篇关于将UIPickerView与自定义值一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!