UIPickerView 按标题设置选定行 [英] UIPickerView Set Selected Row by Title
问题描述
我正在尝试从包含位置列表的 UIPickerView 的代码中选择一行.选择器视图的内容在运行时从服务器加载,我有用户上次登录时使用的位置.
I'm trying to select a row from code of a UIPickerView that holds a list of locations. The pickerview's content is loaded at runtime from a server, and I have the location the user used when they logged in last.
我知道我可以使用 [pickerview selectrow:int ...]
通过数字选择一行,但我需要将前一个位置与选择器中的位置匹配才能获得该行数字.我一直无法找到帮助我做到这一点的方法.
I know I can use [pickerview selectrow:int ...]
to select a row by the number, but I need to match the previous location to the location in the picker to get the row number. I haven't been able to find method that helps me do that.
如果我一直不清楚,我实际上是在尝试通过行的标题在 UIPickerView
中找到元素的行号.
If I have been unclear, I am essentially trying to find the row number of an element in a UIPickerView
via the title of the row.
谢谢!
推荐答案
如果你的选择器只显示 NSStrings
你可以这样做.
If your picker only shows NSStrings
you could do this.
NSUInteger index = [locationsArray indexOfObject:@"London"];
这篇关于UIPickerView 按标题设置选定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!