views:

304

answers:

2

I think this is a quick question and answer - I'm reading a dictionary entry for a detail view which is pushed from a tableview row. but in the detail view, when I'm picking up the data to display (as an HTML page) I'm getting the message: incompatible Objective-C types initializing 'struct NSDictionary *'. expected 'struct NSString *' Could someone help as to what I've done wrong and how it needs correcting. Thanks in advance

The code is here:

- (void)viewDidAppear:(BOOL)animated {
NSLog(@"didappear");
NSString *url = definition; // WARNING MESSAGE IS HERE
//self.glossaryWordDefinition.text = definition;
[glossaryWordDefinition loadRequest:
 [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                      pathForResource:url
                                                      ofType:@"html"] isDirectory:NO]]];
[super viewDidAppear:animated];

}

+1  A: 

Your 'definition' variable seems to be declared as a NSDictionary *, and you are trying to assign it to a NSString *. You probably mean something like this:

NSString *url = [definition valueForKey:@"some key"];
Zoran Simic
Thanks for this. The problem I have, I THINK(?), is that as my initial glossary view/table is a sectioned (A to Z) dictionary with an array for each term within each letter indexed by Item 0, 1 etc., I cannot then reference row in my detailviewcontroller as row is undeclared and I don't have a key. Perhaps I should instead declare it as an array? Please can you help.
Maxwell Segal
Can you post how you create 'definition'? Or something indicating its structure. I don't understand what you have in 'definition'. I think I or someone else could help if you described that.
Zoran Simic
A: 

Try this, as far as i understand from the given data,

NSString *url = [definition objectAtIndex:row];

row is the indexpath value of the selected row, declared at the didSelectIndexPath method,

NSInteger row = [indexPath row];
Nithin
otherwise, need to see some more code of yours, the creation of definition and didSelectRowAtIndexPath method
Nithin
Thanks for this. I have a top-level tableview that is in a glossaryviewcontroller. It is sectioned by each letter of the alphabet and then when a didselectrow is actioned I push a detailviewcontroller. The problem then is that in the detailviewcontroller.m I cannot reference row as it is undeclared and I can't use key because it's an array. I seem to be going round in circles on this one. Any help will be appreciated. The whole thing is supposed to work just like a dictionary with sectioned A-Z then drill-down to a definition.
Maxwell Segal
then you might be creating the dictionary with values and keys. In that case you might be requiring to use the method given by Zoran Simic. or declare row asNSUInteger row = [indexPath row];
Nithin

related questions