I do the following:
myAppDelegate file
I’m parsing an xml file and set its content to NSMutableArray * catalogue, this way:
NSMutableArray * catalogue;
NSMutableDictionary * item;
NSString * currentElement;
NSMutableString *currentName, *currentUrl;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"ended element: %@", elementName);
if ([elementName isEqualToString:@"catalog"]) {
// save values to an item, then store that item into the array...
[item setObject:currentName forKey:@"name"];
[item setObject:currentUrl forKey:@"url"];
[catalogue addObject:[item copy]];
}
}
myUiViewController class
- (void)viewDidLoad
{
[super viewDidLoad];
nameCatalog = [myAudiAppDelegate sharedAppDelegate].catalogue;
NSLog(@"noul sir format %@", nameCatalog);
}
This is what my nameCatalog looks like:
{
name = "Audi TT Coup\U00e9";
url = "http://host_server/uploads/modeles_pdf/43_TT_Coupe_TT_Roadster_Catalogue_Tarifs_20110428.pdf";
},
{
name = "Audi TT Roadster";
url = "http://host_server/uploads/modeles_pdf/42_TT_Coupe_TT_Roadster_Catalogue_Tarifs_20110428.pdf";
}
What I don’t know is…how do I get the name value from there to put it in a tableView?
This is my method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.text = [nameCatalog objectAtIndex:indexPath.row];
return cell;
}
But I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized
How should I acces nameCatalog?Thanks
Following is the solution for you problem…
nameCatalog is your NSMutableArray. [nameCatalog objectAtIndex:indexPath.row] returns a NSMutableDictionary. And you have to get the value by using valueForKey from that.