开发者

NSArray setup and concept for datasource for uipicker

i need some help with nsarrays and uipicker

i have a table of data consisting of columns a,b,c,d and rows m1,m2,m3,m4 each cell in the table has 2 values an upper and lower limit

so cell m3,b has the values 20 and 25 for example

sorry if this is not very clear, i wanted to insert a picture of the table but i don't have enough reputation points to do so

anyway i simply want to represent thi开发者_StackOverflows data table in a uipickerview, so that component 0 has the rows m1,m2,m3 etc component 1 has the columns a,b,c,d etc and column 2 and 3 show the upper and lower limits

i think to do this needs a 2d array, but i don't know how to create the datasource properly

can anyone please advise

many thanks


herewith my solution to the question i asked several weeks ago it might be of use to someone else who knows?

this went in my view did load

    //integer to hold the current row of component 0, this is set to "0" when the view loads.
component0 = 0;
component1 = 0;

    // get the plist

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

    // Assign the contents of the plist to a NSDictionary for processing
mypickervalues = [[NSDictionary alloc] initWithContentsOfFile:path];

    // Creats an array from the keys which we will then use as labels in the picker.

NSArray *sortArray = [[NSArray alloc] initWithArray:[mypickervalues allKeys]];

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

[sortArray release];

NSArray *sortArray2 = [[NSArray alloc] initWithArray:[[mypickervalues objectForKey:[wheelone objectAtIndex:component0]]allKeys]]; 

wheeltwo = [[NSArray alloc] initWithArray:[sortArray2 sortedArrayUsingSelector:@selector(localizedStandardCompare:)]];
[sortArray2 release];


    // setup uipicker and assign to myPicker
myPicker = [self setupPicker];

    // Loads the data linked to the appropriate field in the table of data supplied.
wheelthree = [[NSMutableArray alloc] initWithArray:[[mypickervalues objectForKey:[wheelone objectAtIndex:component0]] objectForKey:[wheeltwo objectAtIndex:component1]]];

hope somebody can advise on the above code, but it seems to work ok for me so far

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜