I'm trying to remove an array from my NSDictionary (deleting an object from my tableview) with the code below, however for some reason I get a crash at this line:
[self.friendData removeObjectAtIndex:indexPath.row];
with this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI removeObjectAtIndex:]: unrecognized selector sent to instance 0x1c0618e20'
Any idea why this is and what the fix would be? See console info for self.friendData and code below:
ViewController.h
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentControl;
@property (weak, nonatomic) IBOutlet UITableView *sidetableView;
@property (strong, nonatomic) NSMutableArray *myFriendData;
@property (weak, nonatomic) IBOutlet UITableView *neighboursView;
@property (strong, nonatomic) NSMutableArray *friendData;
@property (strong, nonatomic) NSMutableArray *neighbourData;
@property (strong, nonatomic) IBOutlet UITableView *friendsView;
ViewController.m
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.sidetableView) {
return UITableViewCellEditingStyleDelete;
}
if (tableView == self.friendsView) {
return UITableViewCellEditingStyleDelete;
}
else {
return UITableViewCellEditingStyleNone;
}
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
if (tableView == self.friendsView) {
NSMutableDictionary *nodeData = [[self.friendData objectAtIndex:indexPath.row] mutableCopy];
NSString *nid = [nodeData objectForKey:@"nid"];
[nodeData setObject:nid forKey:@"nid"];
[self.friendData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[DIOSNode nodeDelete:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"node deleted!");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"could not delete node!");
}];
} else {
NSMutableDictionary *nodeData = [[self.myFriendData objectAtIndex:indexPath.row] mutableCopy];
NSString *nid = [nodeData objectForKey:@"nid"];
[nodeData setObject:nid forKey:@"nid"];
NSLog(@"%@",nid);
[self.myFriendData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[DIOSNode nodeDelete:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"node deleted!");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"could not delete node!");
}];
}
}
}
Console self.friendData:
This is the frienddata (
{
address2 = "street";
body = "nfkkdkckmfkekxkx\n";
childrenunder = No;
city = "<null>";
"emergency facility" = Yes;
friendphoto = "files/stored/1504910599.jpg";
nid = 1796;
"node_title" = "josh";
phone = 2369893091;
"postal code" = V;
"property type" = House;
"special skills" = "med";
"star rating" = 1;
supervision = No;
uid = 47;
uid2 = 182;
}