I am currently parsing some xml that looks like this:
<Rows> <Row MANUFACTURERID="76" MANUFACTURERNAME="Fondont" ISMANU="F" ISAUTO="F"/> <Row MANUFACTURERID="18" MANUFACTURERNAME="Anti" ISMANU="T" ISAUTO="T"/> </Rows>
I analyze it so that there is an array of dictionaries (each dictionary contains four string values โโin it).
Then I pass the ManufacturerName name to my startSortingTheArray method like this
if (dataSetToParse == @"ICMfg") // ICMfg is a string passed to this view from the parent view cell selection enabling me to pass different data sets to this view { //Filter results (ISAUTO = T) NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"ISAUTO",@"T"]; NSArray *filteredArray = [myDataArray filteredArrayUsingPredicate:predicate]; //Passes Manufacturer strigs over to startSortingtheArray method [self startSortingTheArray:[filteredArray valueForKey:@"MANUFACTURER"]]; }
So, here all producer names are sent to my method as an array of strings. Then I use this array to configure all my partitions / index scroller. The method below shows how I do it.
//method to sort array and split for use with uitableview Index - (IBAction)startSortingTheArray:(NSArray *)arrayData { //If you need to sort incoming array alphabetically use this line of code //TODO: Check values coming in for capital letters and spaces etc sortedArray = [arrayData sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; //If you want the standard array use this code //sortedArray = arrayData; self.letterDictionary = [NSMutableDictionary dictionary]; sectionLetterArray = [[NSMutableArray alloc] init]; //Index scrolling Iterate over values for future use for (NSString *value in sortedArray) { // Get the first letter and its associated array from the dictionary. // If the dictionary does not exist create one and associate it with the letter. NSString *firstLetter = [[value substringWithRange:NSMakeRange(0, 1)] uppercaseString]; //uppercaseString puts lowercase values with uppercase NSMutableArray *arrayForLetter = [letterDictionary objectForKey:firstLetter]; if (arrayForLetter == nil) { arrayForLetter = [NSMutableArray array]; [letterDictionary setObject:arrayForLetter forKey:firstLetter]; [sectionLetterArray addObject:firstLetter]; // This will be used to set index scroller and section titles } // Add the value to the array for this letter [arrayForLetter addObject:value]; } //Reload data in table [self.tableView reloadData]; }
from here I do a few actions related to setting the table view after [self.tableView reloadData]; called out. The main thing is that I set the cell with string values โโto an array.
//Display cells with data NSArray *keys = [self.letterDictionary objectForKey:[self.sectionLetterArray objectAtIndex:indexPath.section]]; NSString *key = [keys objectAtIndex:indexPath.row]; cell.textLabel.text = key;
when the cell is then selected, the string value inside the cell is then sent back to the main view and used later as a search parameter ... The fact is that I configure several parameters that will be used as a single search string.
Looking back at the XML that I parsed
<Rows> <Row MANUFACTURERID="76" MANUFACTURERNAME="Fondont" ISMANU="F" ISAUTO="F"/> <Row MANUFACTURERID="18" MANUFACTURERNAME="Anti" ISMANU="T" ISAUTO="T"/> </Rows>
These are the column values โโinside the SQl table that have the MANUFACTURERID key value, which is also contained in other tables that I am analyzing. I would like to use these key values โโto limit / refine other queries, but I just canโt figure out how to pass them to the parent view, where I configured all the search parameters, that is, my question is how to save a dictionary of values โโthat is related to tableview selection users from the preview. Therefore, I can pass one or more of these values โโback to the subtitle of another data set to limit the information displayed depending on previous user choices.
It took me about an hour to print. Hope this makes sense, I'm still pretty new to iOS and Objective-C development, and this concept really pushes my capabilities and before I get to it and end up creating a bit of crap that I will have to fix later, I hope that one or some of you will be able to provide you with your experience in this type so that I can get it for the first time :)
If you need me to clarify anything or provide you with more information to help you help me, just let me know.
Thanks in advance!