I am trying to send an array that loaded with uitableviewcell selected values as dictionary from a viewcontroller (ServicetypesViewController) to load in another array of other viewcontroller(JobcreationViewController) by tapping the done button.
The existing way implemented only sending 1 value by using objctedAtIndex:i and it's sending only 1 value without any crashes
but when I wanted to send multiple selected values with "selectedServiceType" NSDictionary to Jobcreationcell by using a forkey it's crashes and throwing the following execemption.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKeyedSubscript:]: unrecognized selector sent to instance 0x1c065da90'
Getting Selected values and loading to "selected_ids" array. (ServicetypesViewController)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(_selectedIndexes == nil)
{
self.selectedIndexes = [NSMutableArray array];
}
if([_selectedIndexes containsObject:indexPath])
{
[_selectedIndexes removeObject:indexPath];
[selected_ids removeObject:[arrayOfServiceTypes objectAtIndex:indexPath.row]];
NSLog(@"SELECTEDIDS%@",selected_ids);
}
else
{
[_selectedIndexes addObject:indexPath];
NSLog(@"_selectedIndexes%@",_selectedIndexes);
[selected_ids addObject:[arrayOfServiceTypes objectAtIndex:indexPath.row]];
NSLog(@"SELECTEDIDS%@",selected_ids);
}
}
Done Button Event when sending whole selected dictionary (ServicetypesViewController)
- (IBAction)doneButtonAction:(id)sender
{
NSDictionary *selectedServiceTypeDict = [[NSDictionary alloc]init];
selectedServiceTypeDict = [NSDictionary dictionaryWithObject:selected_ids forKey:@"selected_services"];
[self.selectedServiceTypeDelegate getSelectedServiceType:selectedServiceTypeDict];
NSLog(@"selectedServiceTypeDict%@",selectedServiceTypeDict);
[self navigationLeftButtonAction:self.navigationLeftButton];
}
Get the data to (jobcreationViewController)
-(void)getSelectedServiceType:(NSDictionary *)selectedServicesType
{
selectedServiceType = [[NSArray alloc]initWithObjects:[selectedServicesType valueForKey:@"selected_services"], nil];
NSLog(@"SST%@",selectedServiceType);
[self.tableView reloadData];
}
Even App crashes I can see the NSLog - SST responses correctly. I tried many methods but only I can send 1 value out of other selected values. Please help me, by providing code snippets according to my codes in answer. Thanks in Advance.
Edited part
Following are the codes how can I send single value to jobcreationviewcontroller
- (IBAction)doneButtonAction:(id)sender
{
NSDictionary *selectedServiceTypeDict = [[NSDictionary alloc]init];
for(int i=0; i<selected_ids.count; i++)
{
if([_selectedIndexes objectAtIndex:i ])
{
selectedServiceTypeDict = selected_ids[i];
}
}
[self.selectedServiceTypeDelegate getSelectedServiceType:selectedServiceTypeDict];
NSLog(@"selectedServiceTypeDict%@",selectedServiceTypeDict);
[self navigationLeftButtonAction:self.navigationLeftButton];
}
-(void)getSelectedServiceType:(NSDictionary *)selectedServicesType
{
selectedServiceType = [[NSArray alloc]initWithObjects:selectedServicesType, nil];
NSLog(@"SST%@",selectedServiceType);
[self.tableView reloadData];
}