以编程方式添加UITextField在iPad上返回nil

时间:2017-08-02 11:15:19

标签: ios objective-c ipad uiview uitextfield

我已在UIView ..

中以编程方式添加了UITextField
UITextField *tf = [[UITextField alloc] initWithFrame:CGRectMake(0, (12*(i))+(30*i), screenWidth - 16, 30)];
            NSLog(@"Y: %d", (12*(i))+(30*i));
            tf.placeholder = [inputTypes objectAtIndex:0][@"label"];
            tf.borderStyle = UITextBorderStyleRoundedRect;
            //tf.textAlignment=NSTextAlignmentCenter;
            tf.tag = [inputTypes objectAtIndex:0][@"remote_id"];

            //NSLog(@"KA: %@ ",[inputTypes objectAtIndex:0][@"remote_id"]);

            tf.keyboardType = UIKeyboardTypeNumberPad;

            [_viewForDynamicFields addSubview:tf];

并希望从该文本字段中访问值...我为此实现了以下代码..

UITextField *t = [_viewForDynamicFields viewWithTag:[inputTypes objectAtIndex:0][@"remote_id"]]; NSString *value = t.text;

它在模拟器或iPhone上工作正常。但在iPad上,它总是返回值参数nil。

0 个答案:

没有答案