ScrollView中的UITextField不会在iOS中显示键盘

时间:2014-04-09 12:35:48

标签: ios uiscrollview uitextfield uitextfielddelegate

我在UIView中有10个文本字段,我已将视图添加到scrollView。在那5个textFields将被显示,其他将被滚动。

在我的textFieldDidBeginEditing

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag>=4)
    {
        CGRect viewframe=contentsOfView.frame;
        viewframe.origin.y=viewframe.origin.y-100;
        contentsOfView.frame=viewframe;

    }
}

在我的textFieldDidEndEditing

-(void)textFieldDidEndEditing:(UITextField *)textField
{

    if(textField.tag>=4)
    {
        CGRect viewframe=contentsOfView.frame;
        viewframe.origin.y=viewframe.origin.y+100;
        contentsOfView.frame=viewframe;
    }

}

如果我滚动屏幕显示下一个文本字段,屏幕上显示的前5个字段将完美运行。如果我点击它,键盘就不会出现。

[contentsOfView addSubview:nameField];
[contentsOfView addSubview:mobileNumberField];
[contentsOfView addSubview:passwordField];
[contentsOfView addSubview:taxiNumberfield];
[contentsOfView addSubview:emailIdField];
[contentsOfView addSubview:taxiTypeField];
[contentsOfView addSubview:licenseNumber];
[contentsOfView addSubview:nricNumber];
[contentsOfView addSubview:noOfPassengerField];
[contentsOfScrollView addSubview:contentsOfView];
 [self.view addSubView:contentScrollView ];

的TextField

 nameField.borderStyle=UITextBorderStyleLine;
nameField.layer.borderWidth=1.0;
nameField.layer.borderColor=[[HexColorCode colorWithHexastring:@"c88202" ] CGColor];
nameField.keyboardType=UIKeyboardTypeNamePhonePad;
nameField.placeholder=@"NAME";
nameField.backgroundColor=[UIColor whiteColor];
 UIView *  paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
nameField.leftView = paddingView;
nameField.leftViewMode = UITextFieldViewModeAlways;
nameField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
nameField.delegate=self;
nameField.tag=1;

1 个答案:

答案 0 :(得分:1)

删除contentView将对象添加到contectScrollView

[contentScrollView addSubView: nameField];
[self.View addSubView:contentScrollView];

这可能对你有帮助。