键盘响应在ios中缓慢

时间:2014-12-03 06:56:39

标签: ios xcode

我正在创建动态屏幕并动态创建文本字段 当我触摸文本字段并开始写入时,我的键盘响应很慢,并且在屏幕上显示字符时需要大约3-4秒。 我该如何解决这个问题?提前致谢。

    - (BOOL) textFieldShouldBeginEditing:(UITextField *)textField
{
    NSInteger componentType;
    BOOL isEditable = YES;


    for (int i = 0; i < self.screenComponentData.count; i++)
    {
        if ([self.keyboardType[i] intValue] == NUMERIC)
        {
            [textField setKeyboardType:UIKeyboardTypeNumberPad];

        }
        else if([self.keyboardType[i] intValue] == ALPHA)
        {
            [textField setKeyboardType:UIKeyboardTypeAlphabet];

        }
        else if([self.keyboardType[i] intValue] == ALPHANUMERIC)
        {
            [textField setKeyboardType:UIKeyboardTypeDefault];
        }

        NSString *str = [self.entityMap objectAtIndex:i];
//        str = [str substringFromIndex:2];
        if (textField.tag == [str intValue])
        {
          componentType = [self.screenComponentData[i][3] intValue];
            if ([self.screenComponentData[i][7] characterAtIndex:27]  == NON_EDITABLE)
            {
                isEditable = NO;
            }
            break;
        }
    }

    if (componentType == DATE_PICKER || componentType == TIME_PICKER || componentType == VALUE_PICKER)
    {
        [self textFieldTouched:textField];
        return NO;
    }
    else if(isEditable == NO)
    {
        //Dont show picker  & dont allow user to edit too.SHOW DEFAULT TEXT
        return NO;
    }
    else
    {
        return YES;
    }
}


- (void) textFieldTouched:(UITextField *)textField
{
    NSArray *test1;
    NSArray *compoType;
    NSArray *tag_Table_Name;  //<--table to where to get data
    for (int index = 0; index < self.componentType.count ; index++) {
//   pooja's code'
            if (textField.tag ==60  ||textField.tag ==865 ||textField.tag ==1202 || textField.tag==48)
             {

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];


            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
        test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@",tag_Table_Name[0][0]]];

                 if (self.textField.tag== 61)  {
                        textField.text=@"";
                 }

        }else if (textField.tag==61){

         tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@ WHERE COL2='%@'",tag_Table_Name[0][0],self.codeString]];

        }else if (textField.tag==1159){

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@",tag_Table_Name[0][0]]];


        }else if (textField.tag ==1760){

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];


            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@",tag_Table_Name[0][0]]];


        }else if (textField.tag==55){

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@ WHERE COL2='%@'",tag_Table_Name[0][0],self.codeString]];

        }else if (textField.tag==861){

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@ WHERE COL2='%@'",tag_Table_Name[0][0],self.codeString]];

        }else if (textField.tag==108 ||textField.tag == 1154 ||self.textField.tag==66){

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@",tag_Table_Name[0][0]]];

        }else if (textField.tag==1153 ){

            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
            test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@",tag_Table_Name[0][0]]];

        }

        else{
            tag_Table_Name=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL13 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];

            compoType=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL3 FROM %@ WHERE COL0='%@' and COL2='%ld'",TBSYS0001,self.screenId,(long)textField.tag]];
           test1=[DBOperator getDataForQuery:[NSString stringWithFormat:@"SELECT COL1 FROM TB%@",tag_Table_Name[0][0]]];
        }

        if (textField.tag == 64){


            self.tagForFollowUpDate = 64;
            self.configure.getFollowConfigDate = self.tagForFollowUpDate;
        }

        if (textField.tag == 45){


            self.tagForDOB = 45;
            self.configure.getDOB = self.tagForDOB;
        }
    }

        self.textfieldTAG = textField.tag;

    NSInteger compo=[compoType[0][0]intValue];
    //    NSLog(@"COMPO->%d",compo);

    switch (compo) {
        case DATE_PICKER:
            [self displayDatePicker:textField];
            break;

        case TIME_PICKER:
            [self displayTimePicker:textField];
            break;

        case VALUE_PICKER:
        {
            if (self.popOver != nil && [self.popOver isPopoverVisible])
            {
                [self.popOver dismissPopoverAnimated:YES];
            }



            RMPickerViewController *pickerVC = [RMPickerViewController pickerController];
            pickerVC.delegate = self;
            pickerVC.backgroundColor = [UIColor whiteColor];
            //            pickerVC.tintColor = [UIColor yellowColor];
            //            pickerVC.selectedBackgroundColor = [UIColor yellowColor];

            if (self.commanArray != nil && self.commanArray.count > 0)
            {
                [self.commanArray removeAllObjects];
            }
            [self.commanArray addObjectsFromArray:[self getdropListDataWithValue:test1]];  //<---  Value Picker
            [pickerVC showFromRect:textField.frame  inView:self.scrollView];

            break;
        }

        default:
        {
            //To get the values for making the syncData string
            for (int i = 0; i < self.screenComponentData.count; i++)
            {
                NSString *str=[self.entityMap objectAtIndex:i];
                //        str = [str substringFromIndex:2];
                if (textField.tag == [str intValue])
                {
                    [self.valueArray replaceObjectAtIndex:i withObject:textField.text];
                    [self.savingArray replaceObjectAtIndex:i withObject:textField.text];

                    break;
                }
            }

            [textField setKeyboardType:UIKeyboardTypeDefault];

            break;
        }
    }//end of switch case;
;

}// end of textFieldTouched

1 个答案:

答案 0 :(得分:0)

确保主线程不忙,即可能正在运行后台任务,这将减慢进程。它可能不是textfield的问题。

尝试检查一些在后台工作的循环或同步任务..