UITableView单元格/数据消失 [英] UITableView cell/data disappear
问题描述
我有一个分段的tableView,它加载所有部分的所有单元格中的所有数据. 每个单元格中都有一个textField.
I have a segmented tableView that loads all the data in all the cells of all the sections. There is a textField in each cell.
tableview不能完全适合iPad屏幕,并且我无法访问所有不可见的单元格来读取/保存数据.当我在"textField"中进行更改时,然后向上滚动,向下滚动,所有更改都消失了.
The tableview doesn't fit the iPad screen completely, and I can't access all the invisible cells in order to read/save data. And when I make changes in "textField", then scroll up, the scroll down, all the changes are gone.
我需要加载所有单元,甚至一次都看不见,才能访问它们.
I need to load all the cells, even invisible once, to be able to access them.
对不起,几天前我才刚开始使用表格... 我认为这个问题与可重复使用的电池有关,但不确定如何解决.
I am sorry, I just started working with tables a few days ago... I think that this problem has something to do with reusable cells, but not sure how to resolve it.
请寻求您的帮助.
初始化:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 400, 30)] ;
textField.enabled = NO;
cell.accessoryView = textField;
[textField release];
}
UITextField *textField = (UITextField*)cell.accessoryView;
if(indexPath.section == 0)
cell.textLabel.text = [idenInfo objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
cell.textLabel.text = [prodInfo objectAtIndex:indexPath.row];
else if (indexPath.section == 2)
cell.textLabel.text = [visInfo objectAtIndex:indexPath.row];
if(indexPath.section == 0)
textField.text = [idenInfoRez objectAtIndex:indexPath.row];
else if (indexPath.section == 1)
textField.text = [prodInfoRez objectAtIndex:indexPath.row];
else if (indexPath.section == 2)
textField.text = [visInfoRez objectAtIndex:indexPath.row];
textField = nil;
return cell;
}
推荐答案
首先:您不必加载所有单元格,包括不可见的单元格.这就是UITableView和MVC模式的重点:将视图与数据分开.
First of all : you don't have to load all the cells including the invisible ones. That's the whole point of the UITableView and MVC Pattern : separate your views from your data.
当用户更改了textField内部的值时,您要做的是更新数据源(在您的情况下为idenInfoRez
,prodInfoRez
和vizInfoRez
).因此,您必须将UIViewController设置为每个文本字段的委托,并在用户键入内容时更新值.
What you'll want to do is update your Data source (that is idenInfoRez
, prodInfoRez
and vizInfoRez
in your case) when the user has changed a value inside a textField. So you'll have to set your UIViewController as the delegate of each textfield and update the values as the user types in.
这篇关于UITableView单元格/数据消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!