NSArray setup and concept for datasource for uipicker

痞子三分冷 提交于 2019-12-13 06:50:22

问题


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 this 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


回答1:


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



来源:https://stackoverflow.com/questions/6638813/nsarray-setup-and-concept-for-datasource-for-uipicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!