mercredi 25 mars 2015

App crashes when table cell is tapped

I am using the LeveyPopListView. Inside the LeveyPopList View is a table containing jobs in a specific company. All is fine until I tap a job in the pop up list view and I've checked everything. Here's my code:



NSArray* ar_filter=(NSArray*)[self.FilterDictionary objectForKey:@"sub_slots"];
NSInteger numberOfJobs = [[[[[self.FilterDictionary objectForKey:@"sub_slots"] valueForKey:@"company_group"] valueForKey:@"job_count"] objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row] intValue];
NSLog(@"NUMBER OF JOBS: %ld", (long)numberOfJobs);
NSLog(@"ARRAY FILTER: %@", ar_filter);

//MARK: for consolidated view
if([[ar_filter objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row] objectForKey:@"company_group"])
{
if(numberOfJobs > 1)
{
NSString *company_id = [[[[self.FilterDictionary objectForKey:@"sub_slots"] valueForKey:@"company_group"] valueForKey:@"company_id"] objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row];
NSString *company_name = [[[[self.FilterDictionary objectForKey:@"sub_slots"] valueForKey:@"company_group"] valueForKey:@"company_name"] objectAtIndex:[self.jobsTableView indexPathForSelectedRow].row];
NSDictionary *specificCompany = [NSDictionary dictionaryWithObjectsAndKeys:company_id,@"company_id", nil];

if(specificCompany.count>0)
{
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:specificCompany
options:0
error:&error];

if (! jsonData)
{
NSLog(@"Got an error: %@", error);
}
else
{
strJsonStringFilter = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
}

allJobsDictionary = [NSJSONSerialization JSONObjectWithData:[network getData:[NSString stringWithFormat:@"get_all_job_offers?pt_id=%@&filter=%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"pt_id"], strJsonStringFilter]] options:kNilOptions error:nil];
//this contains the jobs that are given by allJobsDictionary
jobsToDisplay=(NSArray*)[allJobsDictionary objectForKey:@"sub_slots"];
//call LeveyPopListView
LeveyPopListView *lplv = [[LeveyPopListView alloc] initWithTitle:company_name options:jobsToDisplay handler:^(NSInteger anIndex)
{
}];

lplv.delegate = self;
[lplv showInView:self.view animated:YES];
strJsonStringFilter = @"";
}
}

- (void)leveyPopListView:(LeveyPopListView *)popListView didSelectedIndex:(NSInteger)anIndex {
NSDictionary *job = (NSDictionary*)[jobsToDisplay objectAtIndex:anIndex];

// Pass data and transit to detail job view controller
[self.parentViewController performSelector:@selector(showJobDetailWith:) withObject:job];
}

-(void)showJobDetailWith:(NSDictionary *)dictionary {
// Pass data to global variable for prepareForSegue method
mapPinSelectedDictionary = dictionary;

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

MTJobDetailTableViewController *smsController=[storyboard instantiateViewControllerWithIdentifier:@"MTJobDetailTableViewController"];

[smsController setJobDetailDict:mapPinSelectedDictionary];
[self.navigationController pushViewController:smsController animated:YES];
}


from LeveyPopListVIew.m



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];

// tell the delegate the selection
if ([_delegate respondsToSelector:@selector(leveyPopListView:didSelectedIndex:)])
[_delegate leveyPopListView:self didSelectedIndex:[indexPath row]];

if (_handlerBlock)
_handlerBlock(indexPath.row);

// dismiss self
[self fadeOut];
}


The app crashes when this line of code [self.parentViewController performSelector:@selector(showJobDetailWith:) withObject:job]; is called. Can anyone help me this. Thank you.




Aucun commentaire:

Enregistrer un commentaire