如何从其编辑的UITextField获取UITableViewCell的索引 [英] How to get UITableViewCell's index from its edited UITextField
问题描述
我正在研究基于iPhone的BI项目。
I'm working on an iPhone based BI project.
我在 UITextViewCell
中有一个 UITextField
, UITextFieldDelegate
指向我的 UITableViewController
,我还没有对 UITextViewCell进行任何子类化
也不是 UITextField
。
I have a UITextField
in a UITextViewCell
, the UITextFieldDelegate
points to my UITableViewController
, I haven't done any sub-classing for the UITextViewCell
nor the UITextField
.
现在在代理人的文本字段结束编辑后
Now after the text field end editing on the delegate
-(void)textFieldDidEndEditing:(UITextField*)textField
我需要知道当前单元格的行索引我正在编辑,有没有办法获取文本字段的父单元格?或者我可以在创建单元格时将某些属性设置为文本字段,如'rowIndex'?我真的需要这个值以保存新文本。
I need to know the row index of the current cell I'm editing, is there any way to get the parent cell of the text field? Or can I set some property to the textfield like 'rowIndex' when I create the cell? I really need this value inorderto save the new text.
谢谢。愿部队与你在一起。
Thank you. May the Force be with you.
推荐答案
你要问的真正问题是如何知道在哪里保存对数据的更改用户在表格单元格中的文本字段中输入数据时的模型。
The real question you are asking is about how to know where to save changes to your data model when the user enters data into a text field within a table cell.
@Ole Begemann建议使用标记
财产完全有效。这取决于您的数据模型。如果您只需要一个整数来标识值在模型中的位置,那么将该整数存储在每个文本字段的标记
属性中。由于您没有使用节,因此行索引等同于拥有整个索引路径。
@Ole Begemann's suggestion to use the tag
property is perfectly valid. It depends on your data model. If all you need is a single integer to identify where the value gets in your model then store that integer in the tag
property of each text field. Since you are not using sections, the row index is equivalent to having the entire index path.
请记住,所有视图都有标记
property。因此,您可以将行索引存储在 cell.contentView.tag
中,并将列索引存储在 textField.tag
中。在文本字段中,您可以使用 textField.superview
获取内容视图。如果不同的视图是 textField
的超级视图,请改用它。
Keep in mind that all views have a tag
property. So you could store the row index in cell.contentView.tag
and the column index in textField.tag
. From the text field you get the content view with textField.superview
. If a different view is the superview of textField
use that instead.
如果你需要比这更复杂的东西识别模型中的位置以保存文本字段内容,然后您需要做一些不同的事情。我要子类 UITableViewCell
或 UITextField
并在子类中定义的属性中存储所需的任何信息。
If you need something more complex than that to identify the location in your model to save the text field contents then you'll need to do something different. I would either subclass UITableViewCell
or UITextField
and store whatever info you need in a property you define in the subclass.
这篇关于如何从其编辑的UITextField获取UITableViewCell的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!