2012-07-03 95 views
0

我有一个UITableView,其中有两个不同的文本字段用于输入文本。有没有办法循环遍历整个tableview,并将其保存到核心数据或将结果复制到一个数组,然后将其保存到核心数据。 下面是创建我的tableview细胞将数据从uitableview保存到核心数据

- (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和问题文本和答复文件添加到阵列中或保存直入我的核心数据模态的代码?

谢谢!

回答

1

您应该采用不同的策略来保存您的数据。用户不必依赖视图(即单元格),只要用户输入该视图,就应该将其放入后备数组中。

你不会说你要显示多少行,但如果有滚动,你几乎可以保证由于缓存而会有比行更少的单元,并且输入的信息将会丢失。细胞又回来了。

出于同样的原因,您不应该将字段添加到cellForRowAtIndexPath:中的单元格中,除非dequeueReusableCellWithIdentifier:返回零...缓存的字段已经具有这些字段。