NSarray of NSdictionaries

1

I am loading some values in UItableview from an array of dictionary values. I then alter the dictionary in the array by adding one more key value object as below

NSMutableDictionary *rowDict = [tableList objectAtIndex:arrayindex];
[rowDict setObject:@"download successfull" forKey:@"downloadstatus"];

but after this when I try retrieveing value from dictionary in the array as below

NSMutableDictionary *rowDict = [tableList objectAtIndex:arrayindex];
NSString *SelectedState = (NSString*)[rowDict objectForKey:@"downloadstatus"];

it crashes ... can any one help me out to fix this

this is the crash display on my consol

 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData objectForKey:]: unrecognized selector sent to instance 0x61a8270'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x003b0be9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x015c15c2 objc_exception_throw + 47
    2   CoreFoundation                      0x003b26fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00322366 ___forwarding___ + 966
    4   CoreFoundation                      0x00321f22 _CF_forwarding_prep_0 + 50
    5   SifyMyStorage                       0x0003b35b -[DownloadListViewController tableView:cellForRowAtIndexPath:] + 314
    6   UIKit                               0x00ec67fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
    7   UIKit                               0x00ebc77f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
    8   UIKit                               0x00ed1450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
    9   UIKit                               0x00ec9538 -[UITableView layoutSubviews] + 242
    10  QuartzCore                          0x009f4451 -[CALayer layoutSublayers] + 181
    11  QuartzCore                          0x009f417c CALayerLayoutIfNeeded + 220
    12  QuartzCore                          0x009ed37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
    13  QuartzCore                          0x009ed0d0 _ZN2CA11Transaction6commitEv + 292
    14  QuartzCore                          0x00a1d7d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
    15  CoreFoundation                      0x00391fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
    16  CoreFoundation                      0x003270e7 __CFRunLoopDoObservers + 295
    17  CoreFoundation                      0x002efbd7 __CFRunLoopRun + 1575
    18  CoreFoundation                      0x002ef240 CFRunLoopRunSpecific + 208
    19  CoreFoundation                      0x002ef161 CFRunLoopRunInMode + 97
    20  GraphicsServices                    0x02ead268 GSEventRunModal + 217
    21  GraphicsServices                    0x02ead32d GSEventRun + 115
    22  UIKit                               0x00e6142e UIApplicationMain + 1160
    23  SifyMyStorage                       0x000020b8 main + 102
    24  SifyMyStorage                       0x00002049 start + 53
)
terminate called after throwing an instance of 'NSException'
iphone
nsarray
asked on Stack Overflow May 8, 2012 by rashii • edited May 8, 2012 by Ilanchezhian

3 Answers

0
See if you have allocated the object and also get the count of dictionary , if the value is being added also see if u have declared NSmutabledictionary or just NSdictionary ... a view at your class having the code would be more helpful to sort out your problem
answered on Stack Overflow May 8, 2012 by Abhishek Singh
0

Ok, a couple things:

-the code you posted is fine. That's not the issue. The (NSString *) cast is unnecessary, but not an issue.

-there is an issue with your NSArray tablelist. If you are really adding only NSMutableDictionary to the array, then either you are doing that wrong, or your array is going out of scope and when you think you are accessing your array, you are accessing something else in memory at that location.

-How are you retaining your reference to tablelist within the controller?

-Change your second code block to this and I'll bet you find your problem (retainCount on one of these object == 0):

NSLog(@"retain count=%d",[tableList retainCount]);
NSMutableDictionary *rowDict = [tableList objectAtIndex:arrayindex];
NSLog(@"retain count=%d",[rowDict retainCount]);
NSString *SelectedState = [rowDict objectForKey:@"downloadstatus"];
answered on Stack Overflow May 8, 2012 by Joel • edited May 8, 2012 by Joel
-2

you r not alloc the NSMutableDictionary so the NSMutableDictionary is empty and your app crashes.

NSMutableDictionary *rowDict = [[NSMutableDictionary alloc]init];

rowDict = [tableList objectAtIndex:arrayindex];
NSString *SelectedState = [rowDict objectForKey:@"downloadstatus"];

best of luck

answered on Stack Overflow May 8, 2012 by Ayaz

User contributions licensed under CC BY-SA 3.0