0

我有一个表单视图,里面有一些 UITextFields。我想在滚动视图中添加表单的视图。

以下是我设计表单及其文本字段的方式:

    - (UIView *)Form
{
    if (!_Form) {

        CGRect frame = CGRectMake(0.0, Height, Width, 310.0);
        UIView *container = [[UIView alloc] initWithFrame:frame];

        CGFloat y = 15.0;
        frame = CGRectMake(15.0, y, width, height);
        UITextField *field = [[UITextField alloc] initWithFrame:frame];
        [
        field.placeholder = @"text";


        CGFloat spacing = 8.0;
        y = frame.origin.y + height + spacing;
        frame = CGRectMake(15.0, y, kDeviceWidth - 2*15.0, height);
        field = [[UITextField alloc] initWithFrame:frame];

        field.placeholder = @"text6";


        frame.size.height = 200.0;

        y = frame.origin.y + height + space;
        frame = CGRectMake(15.0, y, width - 2*15.0, height);
        field = [[UITextField alloc] initWithFrame:frame];

        field.placeholder = @"text1*";



        y = frame.origin.y + height + 16.0;
        CGFloat w = (kDeviceWidth - 2 * 15.0) / 2;
        frame = CGRectMake(15.0, y, w - 2.0, height);
        field = [[UITextField alloc] initWithFrame:frame];

        field.placeholder = @"text3*";


        frame = CGRectMake(15.0 + w + 2.0, y, w - 2.0, height);
        field = [[UITextField alloc] initWithFrame:frame];

        field.placeholder = @"text4*";


        y = frame.origin.y + height + spacevalue;
        frame = CGRectMake(15.0, y, w, height);
        field = [[UITextField alloc] initWithFrame:frame];

        field.placeholder = @"text5";



        y = frame.origin.y + height + 20.0;
        frame = CGRectMake((frame.size.width - 192.0) / 2, y, 192.0, 34.0);



        y = frame.origin.y + height + 8.0;
        frame = CGRectMake((frame.size.width - 192.0) / 2, y, 192.0, 34.0);
    }
    return _Form;
}

我在“textFieldDidBeginEditing”中添加了这个:(signView 是其中包含表单视图的视图)

 UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.signView.frame.size.width, self.signView.frame.size.height)];
       scroll.pagingEnabled = YES;
       [scroll addSubview:self.Form];

       scroll.contentSize = CGSizeMake(self.signView.frame.size.width*self.Form.frame.size.width, self.Form.frame.size.height);

但是当我点击一个文本文件时,表单视图的所有文本字段都会消失。如何将我的滚动视图嵌入到视图中?

谢谢

4

2 回答 2

0

是的,但是您必须通过添加子视图将 UITextField 放入容器中,该容器是您的容器

    if (!_form) {
      //YOUR STUFF then -> add container subview your view  
      [container addSubview:yourTEXTField]
      return container;
    }
    else { 
      return _form;
    }
于 2013-02-27T18:13:28.163 回答
0

你在做return _Form;

是什么_Form

据我了解,您必须返回container。所以让它

return container;

而且您正在制作,UITextField但是您在哪里将 subView 添加到您的视图中,您只是在创建它。

于 2013-02-27T17:22:36.310 回答