Jonesopolis
Jonesopolis

Reputation: 25370

UIPickerView Set Selected Row by Title

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!

Upvotes: 3

Views: 2876

Answers (1)

Ste Prescott
Ste Prescott

Reputation: 1817

If your picker only shows NSStrings you could do this.

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

Upvotes: 3

Related Questions