【发布时间】:2012-12-24 04:06:58
【问题描述】:
我创建了一个表格,该表格可以动态创建自定义为包含文本字段的单元格。当我运行程序时,我可以在 textFields 中输入文本。但是,在退出程序/切换到不同的视图控制器之前,我无法收集输入到其中的文本。您能否建议我应该怎么做才能提取用户输入的文本。
我了解我可以使用以下代码访问单元格...
for (int section = 1; section < [self.tableView numberOfSections]; section++) // section 0: profile picture
{
for(int row = 0; row < [self.tableView numberOfRowsInSection:section]; row++)
{
NSLog(@"section = %d, row = %d", section, row);
NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
UITableViewCell *tempCell = [self tableView:self.tableView cellForRowAtIndexPath:tempIndexPath];
// NSLog(@"tempCell = %@", tempCell);
}
}
但我无法提取其中包含的文本。
我还提到了:Accessing UITextField in a custom UITableViewCell。但我正在寻找更清洁的解决方案。
谢谢!
【问题讨论】:
-
您是否尝试过在自定义单元格类中使用 @ 属性使用 getter setter 来制作文本字段,并使用 tempcell.yourtextfield.text 访问这些内容。
标签: ios uitableview uitextfield uitextfielddelegate