简体   繁体   中英

unrecognized selector sent to instance

sorry guys but i cant get the hang of this array lark. Ive tried everthing to make this work before posting yet another question about arrays. But i cant help it im really stuck

here goes

im simply trying to access a value of a key/value pair :

   NSDictionary *itemsInSection  = [self.patternImagesArray objectAtIndex:indexPath.section];
    NSString *groupTitle = [[[itemsInSection allValues] objectAtIndex:1] objectForKey:@"RequestTitle"];

however when attempting to access the groupTitle it crashes with an invalid pointer "RequestTitle" . Which i can assure you is there.

itemsInSection  __NSCFDictionary *  2 key/value pairs   0x00000001555dc410
[0] struct __lldb_autogen_nspair        
[1] struct __lldb_autogen_nspair        
key __NSCFString *  @"RequestTitle" 0x00000001555be430
value   __NSCFString *  @"Council bill" 0x00000001555db260

The result is fixed and the specific key/value will always appear at position 1 in the dictionary.

I have also tried numerous variations of this line:

NSString *groupTitle = [[[itemsInSection allValues] objectAtIndex:1] objectForKey:@"RequestTitle"];

and

NSString *groupTitle = [[[itemsInSection allValues] objectAtIndex:1] valueForKey:@"RequestTitle"];

and

NSString *groupTitle = [[itemsInSection][1] objectForKey:@"RequestTitle"];

to name just a few.

An NSDictionary is an association of key/value pairs: a given key within the dictionary is unique.

Your NSDictionary (from your output) contains a key called "RequestTitle". If you want to retrieve the value associated with that key, try:

NSString *groupTitle = [itemsInSection objectForKey:@"RequestTitle"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM