0

I am having a Picker View for selecting states(or prefectures for Europe).The current method i am using to populate the Picker View is the following:

in viewDidLoad

_arrayNo = [[NSMutableArray alloc] init];
[_arrayNo addObject:@" AL "];
[_arrayNo addObject:@" AK "];
[_arrayNo addObject:@" AZ "];
[_arrayNo addObject:@" Other "];

and then the usual pickerView delegate and dataSource. With the above code i don't have any issues. But apparantly if i want to add many states/town(let't say over 100) the array method would become hard to maintain.

My question is can i load the states into the array from a list in a file which resides inside the Supporting files folder? For example a file containing:

AL
AK
AZ
AR
CA
...
WI
WV
WI
Other

Thanks in advance.

3 Answers 3

4

Yes. You load the file, parse the strings out of it (probably with componentsSeparatedByString:) and put them in an array.

Sign up to request clarification or add additional context in comments.

Comments

1

You can have a .plist file with the list and then load the plist file root dictionary keys/values into your array.

1 Comment

I'll try that,found already some sample code.I'll post results.
0

Found it!

@property(nonatomic,retain) NSArray *arrayNo;


  NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"townsList" ofType:@"plist"];
  _arrayNo= [[NSArray alloc] initWithContentsOfFile:path];

Thanks for the guidance!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.