【发布时间】:2011-05-27 06:33:52
【问题描述】:
大家好!
我在表格视图的每个单元格中都有一些文本字段,就像这样
如果我在文本字段中输入一些数据并再次上下滚动视图,则文本字段中的数据设置为空。为什么会发生这种情况,我该如何避免这种情况?
以下是我的细胞构造代码
static NSString *CellIdentifier = @"Cell";
CustomCellStudentData *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[[CustomCellStudentData alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell = [[[CustomCellStudentData alloc] initWithFrame:CGRectZero reuseIdentifier:nil] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
switch(indexPath.section)
{
case 0:
switch (indexPath.row)
{
case 0:
{
tfText[0] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)];
cell.accessoryView = tfText[0];
tfText[0].delegate = self;
tfText[0].text = @"";
tfText[0].placeholder = @"<Student Name>";
cell.primaryLabel.text = @"Student Name: ";
}
break;
case 1:
{
tfText[1] = [[UITextField alloc] initWithFrame:CGRectMake(125,15, 170, 40)];
cell.accessoryView = tfText[1];
tfText[1].delegate=self;
tfText[1].placeholder = @"<Student Age>";
cell.primaryLabel.text = @"Student Age: ";
}
break;
}
提前感谢
【问题讨论】:
标签: iphone objective-c uitableview