自定义单元格在tableview中加载需要时间?

时间:2014-04-01 12:10:53

标签: iphone ios7 delegates tableview custom-cell

你好朋友我问的是桌面视图,

当我使用表视图委托时,我没有在cellForRowAtIndexpath函数,noOfRowInTAble和heightForRowAtIndexPath调用属性中正确使用单元格dequeue,但需要时间来调用ccellForRowAtIndexpath函数, 所以我还添加了cellForRowAtIndexpath函数的代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath )indexPath
{
 DialogCustomCell *cell = nil;
if (_fieldDetailArray && [_fieldDetailArray count] > 0)
{

    if (indexPath.row < [_fieldDetailArray count])
    {
        FieldDetail *fieldObject = (FieldDetail *)[_fieldDetailArray objectAtIndex:indexPath.row];
        NSInteger nibItemNo = [fieldObject.fieldType integerValue];


        NSString *fieldOrientation = fieldObject.fieldOrientation;
        NSString *fieldIsRequired = fieldObject.fieldIsRequired;
        NSString *fieldName =  fieldObject.fieldName;

        if (!cell)
        {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DialogCustomCell" owner:self options:nil];
           cell = (DialogCustomCell *)[nib objectAtIndex:nibItemNo];
            cell.delegate  = self;
            cell.fieldId = fieldObject.fieldId;
        }
        switch (nibItemNo)
        {
            case EDIT_TEXT:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.editFrontView setHidden:NO];
                    [cell.editBelowView setHidden:YES];

                    cell.editFrontTextView.delegate = self;
                    if (![fieldIsRequired integerValue])
                    {
                        cell.editFrontLabel.text = [fieldName stringByAppendingString:@"*"];

                        cell.editFrontTextView.placeholder = [fieldName stringByAppendingString:@"*"];
                        cell.editFrontTextView.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    else
                    {
                        cell.editFrontLabel.text  = fieldName;
                        cell.editFrontTextView.placeholder = fieldName;
                        cell.editFrontTextView.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.editFrontLabel.text];
                    [_textFieldkeyArray addObject:cell.editFrontTextView];
                }
                else
                {
                    [cell.editFrontView setHidden:YES];
                    [cell.editBelowView setHidden:NO];
                    cell.editBelowTextField.delegate = self;
                    if (![fieldIsRequired integerValue])
                    {
                        cell.editBelowLabel.text = [fieldName stringByAppendingString:@"*"];

                        cell.editBelowTextField.placeholder = [fieldName stringByAppendingString:@"*"];
                        cell.editBelowTextField.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    else
                    {
                        cell.editBelowLabel.text = fieldName;

                        cell.editBelowTextField.placeholder = fieldName;
                        cell.editBelowTextField.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.editBelowLabel.text];
                    [_textFieldkeyArray addObject:cell.editBelowTextField];
                }
            }
            break;
            case NUMBER :
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.numberFrontView setHidden:NO];
                    [cell.numberBelowView setHidden:YES];
                    cell.numberFrontTextView.delegate = self;
                    if (![fieldIsRequired integerValue])
                    {
                        cell.numberFrontLabel.text = [fieldName stringByAppendingString:@"*"];

                        cell.numberFrontTextView.placeholder = [fieldName stringByAppendingString:@"*"];
                        cell.numberFrontTextView.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    else
                    {
                        cell.numberFrontLabel.text = fieldName;

                        cell.numberFrontTextView.placeholder =fieldName;

                        cell.numberFrontTextView.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.numberFrontLabel.text];
                    [_textFieldkeyArray addObject:cell.numberFrontTextView];
                }else
                {
                    [cell.numberFrontView setHidden:YES];
                    [cell.numberBelowView setHidden:NO];
                    cell.numberBelowTextField.delegate = self;
                    if (![fieldIsRequired integerValue])
                    {
                        cell.numberBelowLabel.text = [fieldName stringByAppendingString:@"*"];

                        cell.numberBelowTextField.placeholder = [fieldName stringByAppendingString:@"*"];
                        cell.numberBelowTextField.text = [_formDataDic valueForKey:cell.fieldId];

                    }
                    else
                    {
                        cell.numberBelowLabel.text = fieldName;

                        cell.numberBelowTextField.placeholder = fieldName;

                        cell.numberBelowTextField.text = [_formDataDic valueForKey:cell.fieldId];


                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.numberBelowLabel.text];
                    [_textFieldkeyArray addObject:cell.numberBelowTextField];
                }
            }
                break;
            case DECIMAL:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.decimalFrontView setHidden:NO];
                    [cell.decimalBelowView setHidden:YES];
                    cell.decimalFrontTextView.delegate = self;
                    if (![fieldIsRequired integerValue])
                    {
                        cell.decimalFrontLabel.text = [fieldName stringByAppendingString:@"*"];

                        cell.decimalFrontTextView.placeholder = [fieldName stringByAppendingString:@"*"];
                        cell.decimalFrontTextView.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    else
                    {
                        cell.decimalFrontLabel.text = fieldName;

                        cell.decimalFrontTextView.placeholder = fieldName;
                        cell.decimalFrontTextView.text = [_formDataDic valueForKey:cell.decimalFrontTextView.placeholder];
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.decimalFrontLabel.text];
                    [_textFieldkeyArray addObject:cell.decimalFrontTextView];
                }else
                {
                    [cell.decimalFrontView setHidden:YES];
                    [cell.decimalBelowView setHidden:NO];
                    cell.decimalBelowTextField.delegate = self;
                    if (![fieldIsRequired integerValue])
                    {
                        cell.decimalBelowLabel.text = [fieldName stringByAppendingString:@"*"] ;

                        cell.decimalBelowTextField.placeholder = [fieldName stringByAppendingString:@"*"];
                        cell.decimalBelowTextField.text = [_formDataDic valueForKey:cell.fieldId];
                    }
                    else
                    {
                        cell.decimalBelowLabel.text = fieldName;

                        cell.decimalBelowTextField.placeholder = fieldName;
                        cell.decimalBelowTextField.text = [_formDataDic valueForKey:cell.fieldId];

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.decimalBelowLabel.text];
                    [_textFieldkeyArray addObject:cell.decimalBelowTextField];
                }
            }
                break;
            case LIST:
            {
                [_fieldIdDic setObject:cell.fieldId forKey:cell.listLabel.text];
                cell.comboCellList = [[NSArray alloc]initWithArray:fieldObject.fieldComboData];
                if ([fieldOrientation integerValue])
                {
                    if (![fieldIsRequired integerValue])
                    {
                        cell.listLabel.text = [fieldName stringByAppendingString:@"*"];
                        if ([_formDataDic valueForKey:cell.fieldId])
                        {
                            [cell.listButton setTitle:[_formDataDic valueForKey:cell.fieldId] forState:UIControlStateNormal];
                        }else
                        {
                            [cell.listButton setTitle:[fieldObject.fieldComboData objectAtIndex:0] forState:UIControlStateNormal];
                        }
                    }
                    else
                    {
                        cell.listLabel.text = fieldName;
                        if ([_formDataDic valueForKey:cell.fieldId])
                        {
                            [cell.listButton setTitle:[_formDataDic valueForKey:cell.fieldId] forState:UIControlStateNormal];
                        }else
                        {
                            [cell.listButton setTitle:[fieldObject.fieldComboData objectAtIndex:0] forState:UIControlStateNormal];
                        }
                    }


                }

            }
                break;
            case DATETIME:
            {
                if ([fieldOrientation integerValue])
                {
                    if (![fieldIsRequired integerValue])
                    {
                        cell.dateTimeLabel.text = [fieldName stringByAppendingString:@"*"];
                        if ([_formDataDic valueForKey:cell.fieldId]) {
                            [cell.datePicker setDate:[Date convertDateFromString:[_formDataDic valueForKey:cell.fieldId] withDateFormat:DATE_FORMATE]];

                        }
                    }
                    else
                    {
                        cell.dateTimeLabel.text = fieldName;

                        if ([_formDataDic valueForKey:cell.fieldId]) {
                            [cell.datePicker setDate:[Date convertDateFromString:[_formDataDic valueForKey:cell.fieldId] withDateFormat:DATE_FORMATE]];

                        }

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.dateTimeLabel.text];
                }


            }
                break;
            case SIGNATURE_TYPE:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.signatureFrontView setHidden:NO];
                    [cell.signatureBelowView setHidden:YES];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.signatureFrontLabel.text = [fieldName stringByAppendingString:@"*"];

                    }
                    else
                    {
                        cell.signatureFrontLabel.text = fieldName;
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.signatureFrontLabel.text];
                }else
                {
                    [cell.signatureFrontView setHidden:YES];
                    [cell.signatureBelowView setHidden:NO];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.signatureBelowLabel.text = [fieldName stringByAppendingString:@"*"] ;
                    }
                    else
                    {
                        cell.signatureBelowLabel.text = fieldName;

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.signatureBelowLabel.text];
                }

            }
                break;
            case ATTACHMENT:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.attachmentFrontView setHidden:NO];
                    [cell.attachmentBelowView setHidden:YES];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.attachmentFrontLabel.text = [fieldName stringByAppendingString:@"*"];

                    }
                    else
                    {
                        cell.attachmentFrontLabel.text = fieldName;
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.attachmentFrontLabel.text];
                }else
                {
                    [cell.attachmentFrontView setHidden:YES];
                    [cell.attachmentBelowView setHidden:NO];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.attachmentBelowLabel.text = [fieldName stringByAppendingString:@"*"] ;
                    }
                    else
                    {
                        cell.attachmentBelowLabel.text = fieldName;

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.attachmentBelowLabel.text];
                }

            }
                break;
            case CHECKBOK:
            {
                if ([fieldOrientation integerValue])
                {
                    if (![fieldIsRequired integerValue])
                    {
                        cell.checkBoxLabel.text = [fieldName stringByAppendingString:@"*"];
                        if ([_formDataDic valueForKey:cell.fieldId])
                        {
                            [cell.checkBoxBtn setTitle:[_formDataDic valueForKey:cell.fieldId] forState:UIControlStateNormal];
                        }else
                        {
                            [cell.checkBoxBtn setTitle:[fieldObject.fieldComboData objectAtIndex:0] forState:UIControlStateNormal];
                        }
                    }
                    else
                    {
                        cell.checkBoxLabel.text = fieldName;
                        if ([_formDataDic valueForKey:cell.fieldId])
                        {
                            [cell.checkBoxBtn setTitle:[_formDataDic valueForKey:cell.fieldId] forState:UIControlStateNormal];
                        }else
                        {
                            [cell.checkBoxBtn setTitle:[fieldObject.fieldComboData objectAtIndex:0] forState:UIControlStateNormal];
                        }

                    }
                    cell.comboCellList = [[NSArray alloc]initWithArray:fieldObject.fieldComboData];
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.checkBoxLabel.text];
                }

            }
                break;
            case QRCODE:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.qrCodeFrontView setHidden:NO];
                    [cell.qrCodeBelowView setHidden:YES];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.qrFrontCodeLabel.text = [fieldName stringByAppendingString:@"*"];

                    }
                    else
                    {
                        cell.qrFrontCodeLabel.text = fieldName;
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.qrFrontCodeLabel.text];
                }else
                {
                    [cell.qrCodeFrontView setHidden:YES];
                    [cell.qrCodeBelowView setHidden:NO];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.qrBelowCodeLabel.text = [fieldName stringByAppendingString:@"*"] ;
                    }
                    else
                    {
                        cell.qrBelowCodeLabel.text = fieldName;

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.qrBelowCodeLabel.text];
                }
                if ([[_formDataDic allKeys] containsObject:cell.fieldId])
                {
                    [cell.qrCodeBelowBtn setTitle:NSLocalizedString(@"Change QR Code", Nil) forState:UIControlStateNormal];
                    [cell.qrCodeFrontBtn setTitle:NSLocalizedString(@"Change QR Code", Nil) forState:UIControlStateNormal];
                }

            }
                break;
            case BARCODE:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.barCodeFrontView setHidden:NO];
                    [cell.barCodeBelowView setHidden:YES];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.barFrontCodeLabel.text = [fieldName stringByAppendingString:@"*"];

                    }
                    else
                    {
                        cell.barFrontCodeLabel.text = fieldName;
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.barFrontCodeLabel.text];
                }else
                {
                    [cell.barCodeFrontView setHidden:YES];
                    [cell.barCodeBelowView setHidden:NO];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.barBelowCodeLabel.text = [fieldName stringByAppendingString:@"*"] ;
                    }
                    else
                    {
                        cell.barBelowCodeLabel.text = fieldName;

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.barBelowCodeLabel.text];
                }
                if ([[_formDataDic allKeys] containsObject:cell.fieldId])
                {
                    [cell.barCodeBelow setTitle:NSLocalizedString(@"Change BAR Code", Nil) forState:UIControlStateNormal];
                    [cell.barCodeFrontBtn setTitle:NSLocalizedString(@"Change BAR Code", Nil) forState:UIControlStateNormal];
                }

            }
                break;
            case BARCODEEXTERNAL:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.barCodeExternalFrontView setHidden:NO];
                    [cell.barCodeExternalBelowView setHidden:YES];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.barCodeFrontExternalLabel.text = [fieldName stringByAppendingString:@"*"];

                    }
                    else
                    {
                        cell.barCodeFrontExternalLabel.text = fieldName;
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.barCodeFrontExternalLabel.text];
                }else
                {
                    [cell.barCodeExternalFrontView setHidden:YES];
                    [cell.barCodeExternalBelowView setHidden:NO];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.barCodeBelowExternalLabel.text = [fieldName stringByAppendingString:@"*"] ;
                    }
                    else
                    {
                        cell.barCodeBelowExternalLabel.text = fieldName;

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.barCodeBelowExternalLabel.text];
                }

            }
                break;
            case MULTIPLEATTACHMENT:
            {
                if (![fieldOrientation integerValue])
                {
                    [cell.multiAttachmentFronView setHidden:NO];
                    [cell.multiAttachmentBelowView setHidden:YES];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.multiAttachementFrontlabel.text = [fieldName stringByAppendingString:@"*"];

                    }
                    else
                    {
                        cell.multiAttachementFrontlabel.text = fieldName;
                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.multiAttachementFrontlabel.text];
                }else
                {
                    [cell.multiAttachmentFronView setHidden:YES];
                    [cell.multiAttachmentBelowView setHidden:NO];
                    if (![fieldIsRequired integerValue])
                    {
                        cell.multiAttachementBelowlabel.text = [fieldName stringByAppendingString:@"*"] ;
                    }
                    else
                    {
                        cell.multiAttachementBelowlabel.text = fieldName;

                    }
                    [_fieldIdDic setObject:cell.fieldId forKey:cell.multiAttachementBelowlabel.text];
                }
            }
                break;
            }


    }
    else
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DialogCustomCell" owner:self options:nil];
        cell = (DialogCustomCell *)[nib objectAtIndex:SUBMIT];
        cell.delegate = self;
    }
}return cell;
}

0 个答案:

没有答案