NSDictionary *story = [stories objectAtIndex: indexPath.row];
cell.text=[NSString stringwithFormat:[story objectForKey@"message];
i dont knw what exaclty “message ” contains (what is the meaning of objectForKey@”message“)
EDIT CODE
NSString *key =[appDelegate.books objectAtIndex:indexPath.row];
//dict y=@"Name";
NSArray *nameSection = [dict objectForKey:key];
NSDictionary *story = [nameSection objectAtIndex: indexPath.row];
cell.text=[NSString stringwithFormat:[story objectForKey:key]];
NSLog(@"Value Of message: %@", [dict objectForKey:key]);
why my code crashes
If you are more familiar with Java or C# the code is equivalent to something like this:
In Smalltalk-style (and therefore Objective-C too) Object Oriented programming, methods are more like messages to other objects. So a good Objective-C method name should read like an English sentence (Subject-Verb-Object). Because of this working with dictionaries (hash tables) looks like this:
In Java it would be:
Notice how the key (“someKey”) was the first argument in the Java example. In Objective-C you name your arguments with the method name, hence
setObject: forKey:. Also notice that in Objective-C strings start with an @ symbol. That’s because Objective-C strings are different from regular C strings. When using Objective-C you almost always use Objective-C’s @ strings.In C# there is a special syntax for Dictionaries so it becomes:
One important problem that you might encounter if you’re new is the problem of native types.
In Java to add an int to a Dictionary you used to have to do:
Because the primitive types (int, char/short, byte, boolean) aren’t real Objects. Objective-C has this problem too. So if you want to put an int into a dictionary you must use NSNumber like so:
And you pull out the integer like so:
EDIT:
Your code might be crashing if you have a ‘%’ character in your string, since stringWithFormat is just like NSLog in that it takes many arguments. So if story[“message”] is “Hello” then it’ll work fine without extra arguments but if it’s “Hello %@” you need to add one argument to stringWithFormat.