数据未显示在UITableView中的右侧单元格中

时间:2015-02-11 09:44:53

标签: ios objective-c uitableview custom-cell

我的UITableView中有一个部分行为不端。其他部分工作正常。

我需要在tableview的部分显示一个字典,该部分应该根据字典中包含" 1"的项目数返回单元格数。我能够显示标题,但我需要在该部分显示的细节显示在它下面的部分(示例:而不是在第3节中显示数据,它在第三个单元格中显示第4节中的数据)。 这是我到目前为止所得到的:

if(indexPath.section == 3)
{
    NSString *strIncentives = [[self.jobDetailDict objectForKey:@"sub_slots"] objectForKey:@"incentives_and_benefits"];
    NSData *jsonData = [strIncentives dataUsingEncoding:NSUTF8StringEncoding];
    CGSize expectedSize = [self GetTextHightForLable:[NSString stringWithFormat:@"%@",incentives]];
    NSError *error;

    incentives = [NSJSONSerialization
                  JSONObjectWithData:jsonData
                  options:NSJSONReadingMutableContainers|NSJSONReadingMutableLeaves
                  error:&error];

    NSLog(@"DICT: %@", incentives);

    if( error )
    {
        NSLog(@"%@", [error localizedDescription]);
    }
    else
    {
        //MARK: COMMISION
        if (incentives[@"commission"][@"1"])
        {
            //enable flag
            _incentivesAndBenefits = [[UILabel alloc] init];
            _incentivesAndBenefits.textAlignment=NSTextAlignmentJustified;

            [_incentivesAndBenefits setFrame:CGRectMake(15, 5, 290, expectedSize.height+10)];
            _incentivesAndBenefits.text = [NSString stringWithFormat:@"%@", incentives[@"commission"][@"1"]];
            _incentivesAndBenefits.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
            _incentivesAndBenefits.numberOfLines=0;
            [cell addSubview:_incentivesAndBenefits];
            NSLog(@"%@",incentives[@"commission"][@"1"]);
        }
        else
        {
            NSLog(@"%@",incentives[@"commission"][@"0"]);
            //return nil;
        }
        //MARK: EXTRAS
        if (incentives[@"extras"][@"1"])
        {
            //enable flag
            _incentivesAndBenefits = [[UILabel alloc] init];
            _incentivesAndBenefits.textAlignment=NSTextAlignmentJustified;

            [_incentivesAndBenefits setFrame:CGRectMake(15, 5, 290, expectedSize.height+10)];
            _incentivesAndBenefits.text = [NSString stringWithFormat:@"%@", incentives[@"extras"][@"1"]];
            _incentivesAndBenefits.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
            _incentivesAndBenefits.numberOfLines=0;
            [cell addSubview:_incentivesAndBenefits];
            NSLog(@"%@",incentives[@"extras"][@"1"]);
        }
        else
        {
            NSLog(@"%@",incentives[@"extras"][@"0"]);
            //return nil;
        }
        //MARK: FOOD
        if (incentives[@"food"][@"1"])
        {
            //enable flag
            _incentivesAndBenefits = [[UILabel alloc] init];
            _incentivesAndBenefits.textAlignment=NSTextAlignmentJustified;

            [_incentivesAndBenefits setFrame:CGRectMake(15, 5, 290, expectedSize.height+10)];
            _incentivesAndBenefits.text = [NSString stringWithFormat:@"%@", incentives[@"food"][@"1"]];
            _incentivesAndBenefits.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
            _incentivesAndBenefits.numberOfLines=0;
            [cell addSubview:_incentivesAndBenefits];
            NSLog(@"%@",incentives[@"food"][@"1"]);
        }
        else
        {
            //return nil;
            NSLog(@"%@",incentives[@"food"][@"0"]);
        }
        //MARK: TRANSPORT
        if (incentives[@"transport"][@"1"])
        {
            //enable flag
            _incentivesAndBenefits = [[UILabel alloc] init];
            _incentivesAndBenefits.textAlignment=NSTextAlignmentJustified;

            [_incentivesAndBenefits setFrame:CGRectMake(15, 5, 290, expectedSize.height+10)];
            _incentivesAndBenefits.text = [NSString stringWithFormat:@"%@", incentives[@"transport"][@"1"]];
            _incentivesAndBenefits.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
            _incentivesAndBenefits.numberOfLines=0;
            [cell addSubview:_incentivesAndBenefits];
            NSLog(@"%@",incentives[@"transport"][@"1"]);
        }
        else
        {
            NSLog(@"%@",incentives[@"transport"][@"0"]);
            //return nil;
        }
        //MARK: UNIFORM
        if (incentives[@"uniform"][@"1"])
        {
            //enable flag
            _incentivesAndBenefits = [[UILabel alloc] init];
            _incentivesAndBenefits.textAlignment=NSTextAlignmentJustified;

            [_incentivesAndBenefits setFrame:CGRectMake(15, 5, 290, expectedSize.height+10)];
            _incentivesAndBenefits.text = [NSString stringWithFormat:@"%@", incentives[@"uniform"][@"1"]];
            _incentivesAndBenefits.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
            _incentivesAndBenefits.numberOfLines=0;
            [cell addSubview:_incentivesAndBenefits];
            NSLog(@"%@",incentives[@"uniform"][@"1"]);
        }
        else
        {
            NSLog(@"%@",incentives[@"uniform"][@"0"]);
            //return nil;
        }
    }
}
//MARK: Mandatory Requirements
else if (indexPath.section==4) {
    _mandatoryRequirementLabel=[[UILabel alloc]init];
    NSString *strDicription=[[[self.jobDetailDict objectForKey:@"sub_slots"]objectForKey:@"mandatory_requirements"]objectAtIndex:indexPath.row];
    CGSize expectedSize =[self GetTextHightForLable:strDicription];
    [_mandatoryRequirementLabel setFrame:CGRectMake(15, 5, 290, expectedSize.height+10)];
    _mandatoryRequirementLabel.text=strDicription;
    _mandatoryRequirementLabel.font=[UIFont fontWithName:@"GillSans-Light" size:14.0f];
    [cell addSubview:_mandatoryRequirementLabel];
    _mandatoryRequirementLabel.numberOfLines=0;
    _mandatoryRequirementLabel.lineBreakMode = NSLineBreakByWordWrapping;
}

我在这里做错了什么?强制性要求的代码工作正常,返回与API给出的单元格数量相同的单元格数量。 任何帮助将不胜感激。感谢。

PS:激励内部的数据来自解析后的儿子形成的api。

0 个答案:

没有答案