iPhone如何在UITableView中读取数据 [英] iPhone how to read the data in UITableView
问题描述
我正在使用iPhone应用程序,它允许用户编辑表视图中显示的数据.
在此任务中,我使用由UILabel
和UITextField
组成的自定义UITableViewCell
.
编辑完成后,如何读取所有行的UITextField中的值?
I am working on a iPhone application it allows users to edit the data shown in the table view.
In this task I use custom UITableViewCell
which consist of UILabel
and UITextField
.
After editing finish how can I read the values in UITextField of all rows ?
推荐答案
您必须将数据存储在字典中,或将对象存储在textfield的委托方法didEndEditing中.
首先,在cellForRowAtIndexPath:
方法中,设置类似于indexpath.row
You have to store the data in dictionary or an object in the delegate method didEndEditing of textfield.
First of all In cellForRowAtIndexPath:
method set the tag of UITextfield object similar to indexpath.row
希望下面的示例代码可以帮助您
Hope the below sample code helps you
- (void)textFieldDidEndEditing:(UITextField *)textField
{
switch (textField.tag) {
case 0:
objAboutYouClass.name=textField.text;
break;
case 1:
objAboutYouClass.email=textField.text;
break;
case 2:
objAboutYouClass.workRole=textField.text;
break;
case 3:
objAboutYouClass.area=textField.text;
break;
case 4:
objAboutYouClass.managersName=textField.text;
break;
case 5:
objAboutYouClass.securityQuestion=textField.text;
break;
case 6:
objAboutYouClass.answer=textField.text;
break;
default:
break;
}
}
这是我支持的最佳方法.我用过类,也可以用字典来存储内容.
This is the best approach i suppes. I have used class you can also use dictionary to store the content.
快乐的编码.....
hAPPY cODING.....
这篇关于iPhone如何在UITableView中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!