I am having problem with the following code, I need to do some modification on each array within a NSMutableDictionary. When I first added those array into the dictionary, they are "MutableArray", but when I try to do something with them, they become a "NSArray".
here is my code:
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
NSLog(@"cell: %@", cellText);
Boolean flag = false;
NSMutableDictionary *myTempDict = [[NSMutableDictionary alloc] initWithDictionary:self.tableContents copyItems:YES];
for (NSString *key in myTempDict)
{
NSLog(@"1st for");
for(NSString *myString in [myTempDict objectForKey:key])
{
NSLog(@"2nd for");
if([myString isEqualToString:cellText])
{
if([[myTempDict objectForKey:key] isKindOfClass:[NSMutableArray class]])
{
NSLog(@"mutable");
}
else if([[myTempDict objectForKey:key] isKindOfClass:[NSArray class]])
{
NSLog(@"not mutable");
}
[[myTempDict objectForKey:key] removeObject:myString];
break;
NSLog(@"break1");
}
NSLog(@"2nd for end");
}
if(flag)
{
break;
NSLog(@"break2");
}
}
self.tableContents = myTempDict;
[tableView reloadData];
now when I run it, it generate the following error:
- cell: 12-01244476
- 1st for
- 2nd for
- not mutable
- -[__NSArrayI removeObject:]: unrecognized selector sent to instance 0x7c02580
- Current language: auto; currently objective-c
on my viewdidLoad I created those Array to be NSMutableArray, but now its back to NSArray, why? and any idea on how to tackle this problem?
really need help on this.
Thanks