如何在滚动视图中找到以编程方式添加的文本字段

时间:2012-09-10 11:42:12

标签: iphone ios ios5 ios4

在我的scrollView中,我通过单击“添加”按钮以编程方式添加uitextfields。文本字段的数量取决于我按下添加按钮的程度。它可以是'N'个文本字段。 在此字段编辑之后,如何将所有文本字段中的值转换为数组。  如果我编辑了文本字段,就有可能删除其中的条目。那么在单击“保存”按钮的同时在所有文本字段中保存值的方法是什么。 我正在附上我的截图。 提前致谢 Programmatically adding Textfields sample preview

3 个答案:

答案 0 :(得分:3)

使用快速枚举。

NSMutableArray *arr = [NSMutablearray....];
for (UIView *subV in self.view.subviews){
     if([subV isKindOfClass:[UITextField class]]){
        //store it in a NSDictionary, so later can still know which 
        //textField your text belongs,
         NSDictionary *tempDic = [NSDictionary dictionaryWithObjectAndKey:subV.txt 
                           ,subV.tag,/*or subVw.placeholder*/,nil];
        [arr addObject:tempDic];

   }
}

答案 1 :(得分:0)

您可以通过遍历scrollview

的子视图数组来获取所有文本字段
for (UIView *subView in scrollview) {
    //check if the subView is a textfield by for example matching a certain tag
    //save text of textfield
}

答案 2 :(得分:0)

在创建textField时,然后将tagValue分配给每个textField,然后使用标记值....访问textField。

UITextField *txtField = (UITextField *) [scrollView viewWithTag:tag];