简体   繁体   English

UIPickerView 选择更新 UITextFields 的 NSArray

[英]UIPickerView selection updates NSArray of UITextFields

I have created a UIScrollView that contains a dynamic number of UIViews.我创建了一个包含动态数量的 UIViews 的UIScrollView Inside each UIView will be a dynamic number of UItextField s.每个 UIView 内部将是一个动态数量的UItextField s。

The view itself looks like this视图本身看起来像这样

在此处输入图片说明

This white boxes are the UIViews and the black boxes are the UITextfield s.这个白框是UITextfield ,黑框是UITextfield s。

I have a method that puts these UITextfield s into an array of arrays.我有一种方法可以将这些UITextfield放入数组数组中。 So you have an array of UIView s then in each array there is an array of UITextfield s.所以你有一个UIView数组,然后在每个数组中有一个UITextfield数组。

that code looks like this.该代码看起来像这样。

for(int i = 0; i< viewcount; i++) {
        color = color + 20;
        NSLog(@"%f", color);
        CGFloat y = i * 91;

        UIScrollView *axisContainerScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, y,self.view.frame.size.width, 90.0)];
        axisContainerScrollView.contentSize = CGSizeMake(600.0, 90.0);
        axisContainerScrollView.backgroundColor = [UIColor whiteColor];
        [htmlContainerScrollView addSubview:axisContainerScrollView];

//        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,self.view.frame.size.width, 90.0)];
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 640.0, 90.0)];
        view.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:(1.0/i)];;
        [axisContainerScrollView addSubview:view];

        int cutCount = [cutsString integerValue];
        int positions = (view.frame.size.width/cutCount);

        for (int i = 0; i < cutCount; i++) {
            //first one
            UITextField *cutField = [[UITextField alloc] initWithFrame:CGRectMake(((positions*i)-(20/2)+(positions/2)), 25, 20, 20)];
            cutField.textColor = [UIColor colorWithRed:0/256.0 green:84/256.0 blue:129/256.0 alpha:1.0];
            cutField.font = [UIFont fontWithName:@"Helvetica-Bold" size:25];
            cutField.backgroundColor=[UIColor whiteColor];
            [view addSubview:cutField];

            [columnArrayOfTextFields addObject:cutField]; // array of textfields
        }
        [rowArrayOfTextFields addObject:columnArrayOfTextFields]; // array of arrays

    }

What I would like help with is how to then step through each UITextField and enter a value from a UIPickerView .我想要帮助的是如何逐步遍历每个UITextField并从UIPickerView输入一个值。 so as you select values you populate each UITextField from left to right and progress downwards through each UItextField .所以当您选择值您填充每个UITextField由左到右,并通过每个向下进步UItextField

I have a gesture recognizer for the UIPickerView where it calles a method like this我有一个UIPickerView的手势识别器,它调用这样的方法

UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerTap:)];

I think the NSArray of NSArrays is a good start but I'm just not sure how to progress from here.我认为 NSArrays 的NSArray是一个好的开始,但我不确定如何从这里开始。

If I understand correctly, you can use the tag property of the UIView如果我理解正确,您可以使用UIViewtag属性

What I usually do (since I've come to this problem myself) is :我通常做的(因为我自己也遇到过这个问题)是:

A . A You have a known number of elements and you assign the tags from 1 to n您有已知数量的元素,并将标签从1分配到n

B . B If you can add/delete/or you just have a dynamic number of elements, multiply prime numbers with 1 , 2 , 3 etc.如果您可以添加/删除/或您只有动态数量的元素,请将素数与123等相乘。

  • For example, on line 1 you use prime number 3 .例如,在第1行,您使用质数3 So your text fields will have tags like 3 , 6 , 9 , 12 , 15 and 18所以你的文本字段会有像3 , 6 , 9 , 12 , 1518这样的标签
  • Then for second line you will use 7 .然后对于第二行,您将使用7 So you will have your text field tagged with 7 , 14 , 21 , 28 , 35 and 43因此,您的文本字段将被标记为71421283543
  • For line 3 you use 11对于第3行,您使用11
  • For line 4 you use 13 and so on ...对于第4行,您使用13等......

There's a lot of way it can be done, these are just on top of my head or actually what I use, if I haven't understood correctly what you want, feel free to let me know.有很多方法可以完成,这些只是我的头顶或我实际使用的,如果我没有正确理解你想要什么,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM