在 UItableview 中迭代 - iphone [英] Iterate in a UItableview - iphone

查看:20
本文介绍了在 UItableview 中迭代 - iphone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由自定义表格单元(FormCell 类型)组成的 uitableivew.每个单元格都有一个标签和文本字段.

I have a uitableivew made up of custom tablecells (of type FormCell). Each cell has a label and textfield.

我想迭代所有值以获取用户输入(换句话说,uitextfields 中写入的内容)

I would like to iterate all the values to get user input (in other words, what is written in the uitextfields)

我已经到了

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FormCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[FormCell class]]) {
}

所以我有细胞,但谁能告诉我接下来要做什么?

so i've got the cells but can anyone let me know what to do next please?

谢谢!

推荐答案

您应该有一个模型对象/集合,用于保存在文本字段中获取/设置的值.

You should have a Model Object / Collection that you use to keep the values that you get / set in your text fields.

不要忘记,当单元格出列时,您必须重置每个文本字段中的文本(因为它是在您的 tableView:cellForRowAtIndexPath: 中重新创建的:以确保它不会在用户滚动时消失.

Don't forget that as cells get dequeued you will have to reset the text in each textfield (as it's re-created in your tableView:cellForRowAtIndexPath: to make sure it doesn't disappear when the user scrolls.

步骤:1. 初始化一个 NSMutableArray (e.g. textFieldValues)2. 在 tableView:cellForRowAtIndexPath: 创建你的单元格.将 textField 文本设置为您的集合中的 [textFieldValues objectAtIndex:indexPath.row]3. 确保你设置了一个 textField 委托(自己?)4. 当 textField 完成编辑后,将值保存在 textFieldValues 数组中.要知道编辑了哪一行,您可以将 TextField 的标签属性设置为 indexPath.row :)

Steps: 1. initialise an NSMutableArray (e.g. textFieldValues) 2. in tableView:cellForRowAtIndexPath: create your cell. Set the textField text to be what you have in your collection to be your [textFieldValues objectAtIndex:indexPath.row] 3. Make sure you set a textField delegate (self ?) 4. When the textField finishesEditing save the value in your textFieldValues array. To know which row was edited you can set the tag property of the TextField to be indexPath.row :)

完成.

这篇关于在 UItableview 中迭代 - iphone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆