ios - 点击表格单元格时应用程序崩溃

标签 ios objective-c uitableview

我正在使用 LeveyPopListView 。 LeveyPopList View 内部有一个包含特定公司职位的表。一切都很好,直到我在弹出 ListView 中点击一个作业并检查了所有内容。 这是我的代码:

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];
}    

来自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];
}

当这行代码时应用程序崩溃:

[self.parentViewController performSelector:@selector(showJobDetailWith:) withObject:job];

被调用。谁能帮我这个。谢谢。

最佳答案

试试这个

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

// Pass data and transit to detail job view controller
UIStoryboard  *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

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

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

关于ios - 点击表格单元格时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29270986/

相关文章:

android - 跟踪 Android/iOS 下移动应用程序的数据库工作负载

iOS - 转到主屏幕并返回应用程序时脉冲动画暂停

iOS:将 uiview 与其他 ViewController View 拆分

android - 已发布的 expo 应用程序,在 iOS 上的 expo 中运行

iphone - 在 iOS GridView 中加载相机胶卷图像非常慢

ios - @property definitions with ARC : strong is the default value, 但基本类型的默认值是多少?

objective-c - Cocoa - 从 XML 加载数据期间应用程序卡住

objective-c - Objective C 中的 BOOL 属性命名

ios - 检测 UITableViewCell 何时离开屏幕

ios - 在 UISearchDisplayController 后面重新加载 UITableView