我试图创建一个注册表单,其中包含大约20个不同的字段分为四个不同的部分。 我为此创建了一个自定义单元格,它包含一个标签和一个UITextField,并且我的桌面视图上有一个字典数组,指示标签的名称应该是什么,以及texftield的标签(因为根据标签我使用UIPicker输入数据)。自定义单元格textfield没有保存在UITableView中的内存
的问题是,当我开始编辑的字段,向下滚动并备份一切变得一团糟,而改变的字段不应该......我碰到这显然是发生了,因为我所以我试图创建一个新的单元格,但这是行不通的,因为它只会初始化我需要的确切数量的单元格的tableview,而只是没有内容的空单元格(标签也不是textfield)里面。
什么是最简单的方法,所以我可以保持我的细胞的每一个不同的内存引用,考虑的事实,我有当按下一个按钮来检索他们的价值观?
我读过this后的建议,但仍然没有关于如何创建单元阵列想法。
任何帮助?
这是我的定义代码:
NSArray *section1 = [[NSArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"100",@"tag",@"Title",@"title",@"title",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"First Name",@"title",@"first_name",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Last Name",@"title",@"last_name",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Job Title",@"title",@"job_title",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Email",@"title",@"email",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Confirm Email",@"title",@"confirm_email",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Password",@"title",@"password",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Confirm Password",@"title",@"conf_password",@"fieldName",nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"tag",@"Phone",@"title",@"phone",@"fieldName",nil],
nil];
....
self.formItems = [[NSArray alloc] initWithObjects:
section1,
section2,
section3,
section4,
section5,
nil];
然后我上的cellForRowAtIndexPath使用的代码如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"freeTrialFormCell";
TSIFreeTrialFormCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TSIFreeTrialFormCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSArray* sectionData = [self.formItems objectAtIndex:indexPath.section];
NSDictionary* myFieldInfo = [sectionData objectAtIndex:indexPath.row];
if ([[myFieldInfo objectForKey:@"fieldName"] rangeOfString:@"password"].location != NSNotFound) {
cell.textField.secureTextEntry = YES;
}
cell.fieldName = [myFieldInfo objectForKey:@"fieldName"];
cell.textField.placeholder = [myFieldInfo objectForKey:@"title"];
cell.textField.tag = [[myFieldInfo objectForKey:@"tag"] integerValue];
cell.label.text = [myFieldInfo objectForKey:@"title"];
return cell;
}
我忘了提及...我正在使用StoryBoarding。 –