UIPickerView Set Selected Row by Title

随声附和 提交于 2019-12-10 20:06:18

问题


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.

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.

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.

Thanks!


回答1:


If your picker only shows NSStrings you could do this.

NSUInteger index = [locationsArray indexOfObject:@"London"];


来源:https://stackoverflow.com/questions/15976162/uipickerview-set-selected-row-by-title

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!