添加其他部分时将编辑后的文本保留在自定义单元格中([tableView刷新数据])

时间:2014-08-30 22:06:02

标签: ios objective-c xcode uitableview

我有一个带有自定义UITableViewCell的nib文件和带有TableView的视图控制器,每个部分包含三个自定义单元格。我还有一个按钮,按下后,添加一个新的部分与另外三个自定义单元格。

我的问题是,我有一个placeholderArray = @“Name”,@“Position”,@“Email”;用于设置每个单元格的文本。而advisorArray包含三个textFields的用户输入。用户输入保存到此数组中,但是当用户按下按钮以添加另一组单元格时,原始的三个单元格文本将更改回textFieldArray而不是用户文本。 我知道[tableView refreshData]是导致这种情况的原因,但我不知道另一种方法是在tableView中添加另一个部分。

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
return sections;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath{
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:@"myCell"];
cell.tag = indexPath.row;

[cell.textField setText:[self.placeholderText objectAtIndex:indexPath.row]];

cell.textField.delegate = self;
cell.textField.tag = indexPath.row;

return cell;
}


- (void)textFieldDidEndEditing:(UITextField *)textField{

if (textField.tag == 0) {
    self.nameString = textField.text;
    [self.advisorsArray replaceObjectAtIndex:0 withObject:self.nameString];
}
if (textField.tag == 1) {
    self.positionString = textField.text;
    [self.advisorsArray replaceObjectAtIndex:1 withObject:self.positionString];
}
if (textField.tag == 2) {
    self.emailString = textField.text;
    [self.advisorsArray replaceObjectAtIndex:2 withObject:self.emailString];
}

}

- (IBAction)addAdvisor:(id)sender {
sections++;
[self.tableView reloadData];
}

1 个答案:

答案 0 :(得分:0)

中的self.placeholderArray是什么
[cell.textField setText:[self.placeholderText objectAtIndex:indexPath.row]];

存储的实际数据在哪里。您的意思是使用self.advisorsArray吗?

相关问题