我有以下代码...
for (j=0; j<20; j++) {
if (j<20) {
txtField = [[UITextField alloc] initWithFrame:CGRectMake(110, txt_Pos_Y, 100, 15)];
txtField.borderStyle = UITextBorderStyleRoundedRect;
txtField.font = [UIFont systemFontOfSize:11];
txtField.tag = j;
txtField.placeholder = @"Enter Value";
txtField.autocorrectionType = UITextAutocorrectionTypeNo;
txtField.keyboardType = UIKeyboardTypeDefault;
txtField.returnKeyType = UIReturnKeyDone;
txtField.clearButtonMode = UITextFieldViewModeWhileEditing;
txtField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
txtField.delegate = self;
[scrollView addSubview:txtField];
[txtField release];
txt_Pos_Y = txt_Pos_Y + 20;
}
该代码创建了 20 个文本字段....当视图加载时,所有文本字段都是可编辑的。现在我想给出值。我想要在哪个文本字段上单击首先,只有那个文本字段是可编辑的,而休息将是不可编辑的。
我给了标签,txtField.tag = j;
现在我无法弄清楚按下或单击了哪个标签?并且无法使我首先单击的 TextField 可编辑,而其余的不可编辑?
我试过这个来检查CalculateMethod() 方法中点击txtField.tag == 1 的条件,但这不起作用。
-(void)CalculateMethod {
UITextField *txtFld = (UITextField*)[scrollView viewWithTag:1];
// I want if TextFeild "txtField.tag == 1" is clicked then Enter this condition
if(txtField.tag == 1){
double a;
a = Var_sqFt * Var_sqMtr;
txtFld.text = [[NSString alloc] initWithFormat:@"%.4f",a];
}
// I want if TextFeild "txtField.tag == 2" is clicked then Enter this condition
if(txtField.tag == 2){ // Here I want Only that
double a;
a = Var_sqFt * Var_sqMtr;
txtFld.text = [[NSString alloc] initWithFormat:@"%.4f",a];
}
}
所以我有2个问题
我想在哪个文本字段上单击首先,只有 TextField 是可编辑的,而 Rest 是 NonEditable ,该怎么做?
哪个 TextField 被点击/触摸/按下,就像我在 CalculateMethod() 方法中尝试过的一样?