Search code examples
nsarraynsdictionaryuipicker

Uipicker componet split to minimise scrolling with large data set


I have the following code to read data from my .plist for use in a UIPicker. This all works fine, but now I want to split my picker as the data in the componet wheel is getting too big meaning too much scrolling.

The componet 0 of the picker has values a1 a2 a3 a4 a5 etc through to z26.

How can I split this component into 2, so that componet 0 is a to z and componet 1 fills with dictionary item 1,2,3 as required:

NSString *path = [[NSBundle mainBundle] pathForResource:@"Picker" ofType:@"plist"];

pickerData = [[NSDictionary alloc]initWithContentsOfFile:path];

NSArray *sortArray = [[[NSArray alloc] initWithArray:[pickerData allKeys]]autorelease];

mainKeys = [[NSArray alloc]  initWithArray:[sortArray sortedArrayUsingSelector:@selector(localizedStandardCompare:)]];

currentValues = [[NSMutableArray alloc] initWithArray:[pickerData objectForKey:[mainKeys objectAtIndex:component0Row]]];

I dont know how to structure the code or the plist to achieve this. Can somebody advise, thanks.

Here is an extract of the plist:

<dict>
    <key>a10</key>
    <array>
        <dict>
            <key>Lower Value</key>
            <integer>-310</integer>
            <key>Upper Value</key>
            <integer>-270</integer>
        </dict>
        <dict>
            <key>Lower Value</key>
            <integer>-318</integer>
            <key>Upper Value</key>
            <integer>-270</integer>
        </dict>
        <dict>
            <key>Lower Value</key>
            <integer>-338</integer>
            <key>Upper Value</key>
            <integer>-290</integer>
        </dict>
        <dict>
            <key>Lower Value</key>
            <integer>-360</integer>
            <key>Upper Value</key>
            <integer>-290</integer>
        </dict>
        <dict>
            <key>Lower Value</key>
            <integer>-620</integer>
            <key>Upper Value</key>
            <integer>-460</integer>
        </dict>
        <dict>
            <key>Lower Value</key>
            <integer>-680</integer>
            <key>Upper Value</key>
            <integer>-520</integer>
        </dict>
    </array>
    <key>a11</key>
    <array>
        <dict>
            <key>Lower Value</key>
            <integer>-330</integer>
            <key>Upper Value</key>
            <integer>-270</integer>
        </dict>
        <dict>
            <key>Lower Value</key>
            <integer>-345</integer>
            <key>Upper Value</key>
            <integer>-270</integer>
        </dict>

etc,etc

Solution

  • this link takes you to the solution to this question

    note! the plist structure needs to change

    NSArray setup and concept for datasource for uipicker