问题
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