UITableView reloadData不能正常工作的时候把它放在Editing Did End IBAction中,知道为什么
我在表格的每个单元格中放置了一个文本字段。 编辑文本字段后,将触发EditingDidEnd
事件。 在处理这个事件的方法中,我尝试使用
[XXXUITableViewController.tableView reloadData];
但它不起作用(委托方法没有被调用)。
如果我尝试像hanlding Tapgesture一样重新加载数据,它的工作就好了。 我可以使用anthoer的方式来使我的应用程序工作,但最好知道为什么reloadData不工作。 任何想法,非常感谢。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ParCellID"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; for(UIView * old in cell.contentView.subviews){ [old removeFromSuperview]; } //add a textfield in Table Cell View ParticleConfigCellView * parCell=[[[NSBundle mainBundle] loadNibNamed:@"ParticleConfigCellView" owner:self options:nil]objectAtIndex:0]; [parCell refreshFromDataSource:[self.dataContainer.data_particleConifig objectAtIndex:indexPath.row]]; [cell.contentView addSubview:parCell]; return cell; } - (IBAction)nameChange:(id)sender { [self savedata]; [self.tableView reloadData];//(not working. Table view delegate methods are not called.) }
在这个方法中,也重新加载你的数组,这是显示在表视图,因为保存新的数据后,你不重新加载新的数据,使其只显示旧的数据。
- (IBAction)nameChange:(id)sender { [self savedata]; [yourArray removeAllObjects]; //then here put new that in yourArray [self.tableView reloadData];//(not working) }
编辑:
还要调用这个方法[self.tableView reloadData];
在你的savedata
方法的最后一行。
每次创build单元格时,都必须分配一个委托文本字段。 如果您使用的是dynamic表格,请在此方法中添加以下代码: cell.yourTextField.delegate = self
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
。
或者,也许你忘了订阅你的课程的协议?
在任何情况下, reloadData
方法都会从数据源更新表中的数据,我不明白为什么在表中的字段中input文本后需要调用此方法。 如果你不保存这个文本,在调用reloadData
方法之后会消失。