簡體   English   中英

添加另一部分時,將編輯后的文本保留在自定義單元格中([tableView刷新數據])

[英]Keep edited text in custom cell when adding another section ([tableView refresh data])

我有一個帶有自定義UITableViewCell的nib文件,以及一個帶有TableView的視圖控制器,該ViewView每節包含三個自定義單元格。 我還有一個按鈕,當按下該按鈕時,將添加一個帶有另外三個自定義單元格的新部分。

我的問題是,我有一個placeholderArray = @“名稱”,@“位置”,@“電子郵件”; 用於設置每個單元格的文本。 和advisorArray包含三個文本字段的用戶輸入。 用戶輸入保存到該數組中,但是當用戶按下按鈕添加另一組單元格時,原始的三個單元格文本將更改回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];
}

什么是self.placeholderArray

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

實際數據存儲在哪里。 您是要使用self.advisorsArray嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM