Iphone 将数据从uitableview保存到核心数据

Iphone 将数据从uitableview保存到核心数据,iphone,uitableview,core-data,uitextfield,Iphone,Uitableview,Core Data,Uitextfield,我有一个UITableView,其中有两个不同的文本字段用于文本输入。是否有一种方法可以在整个tableview中循环,并将其保存到核心数据,或者将结果复制到数组中,然后将其保存到核心数据。 下面是创建我的tableview单元格的代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIden

我有一个UITableView,其中有两个不同的文本字段用于文本输入。是否有一种方法可以在整个tableview中循环,并将其保存到核心数据,或者将结果复制到数组中,然后将其保存到核心数据。 下面是创建我的tableview单元格的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Add Terms to New Set";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

// Configure the cell...
questionTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 250, 30)];
questionTextField.adjustsFontSizeToFitWidth = YES;
questionTextField.textColor = [UIColor blackColor];
//questionTextField.placeholder = @"Put Question Here";
questionTextField.keyboardType = UIKeyboardTypeDefault;
questionTextField.returnKeyType = UIReturnKeyDone;
[questionTextField.layer setBorderColor: [[UIColor grayColor] CGColor]];
[questionTextField.layer setBorderWidth: 0.5];
[questionTextField.layer setCornerRadius:8.0f];
[questionTextField.layer setMasksToBounds:YES];

[questionTextField setEnabled: YES];

answerTextField = [[UITextField alloc] initWithFrame:CGRectMake(400, 10, 250, 30)];
answerTextField.adjustsFontSizeToFitWidth = YES;
answerTextField.textColor = [UIColor blackColor];
//answerTextField.placeholder = @"Put Answer Here";
answerTextField.keyboardType = UIKeyboardTypeDefault;
answerTextField.returnKeyType = UIReturnKeyDone;

[answerTextField.layer setBorderColor: [[UIColor grayColor] CGColor]];
[answerTextField.layer setBorderWidth: 0.5];
[answerTextField.layer setCornerRadius:8.0f];
[answerTextField.layer setMasksToBounds:YES];


[answerTextField setEnabled: YES];

[cell addSubview:questionTextField];
[cell addSubview:answerTextField];
return cell;
}

如何在tableview中循环并将问题文本和答案文本添加到数组中,或直接保存到核心数据模式中


谢谢

您应该采用不同的策略来保存数据。不要依赖视图(即单元格)来保存它,而是应在用户输入后立即将其放入备份阵列中

您不会说要显示多少行,但如果有滚动,您几乎可以保证由于缓存,单元格将少于行,并且当单元格再次返回时,输入的信息将丢失

出于同样的原因,您不应该向
cellforrowatinexpath:
中的单元格添加字段,除非
dequeueReusableCellWithIdentifier:
返回nil…缓存的单元格已经有这些字段