2012-07-03 94 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:返回零...緩存的字段已經具有這些字段。