问题描述
我在表的每个单元格中放置了一个文本字段。编辑完文本字段后,将触发一个 EditingDidEnd
事件。在处理此事件的方法中,我尝试使用
I put a textfield in every cell of the table. And after editing the textfield, an EditingDidEnd
Event will trigger. In the method of hanlding this event I try to use
[XXXUITableViewController.tableView reloadData];
但这不起作用(未调用委托方法)。
but it doesn't work(the delegate method is not called).
如果我尝试通过诸如处理Tapgesture之类的方法 reloadData
,它就可以正常工作。我可以使用其他方式使我的应用正常运行,但是最好知道为什么reloadData无法正常工作。任何想法,非常感谢。
If I try to reloadData
in someway like hanlding Tapgesture, it works just fine. I can use anthoer way to make my app work, but it's better to know why is reloadData not working. Any ideas, thanks a lot.
- (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.)
}
推荐答案
在此方法中,此方法还会重新加载在表视图中显示的数组,因为保存新数据后您不会重新加载新数据,因此其显示为旧
Here in this method also reload your array which is showing in table view because after saving new data you are not reloading new data so that its showing old data only.
- (IBAction)nameChange:(id)sender {
[self savedata];
[yourArray removeAllObjects];
//then here put new that in yourArray
[self.tableView reloadData];//(not working)
}
编辑:
也将此方法称为 [self.tableView reloadData];
savedata
方法的最后一行中的code>。
Also call this method [self.tableView reloadData];
in the last line of your savedata
method.
这篇关于将UITableView reloadData放在“ Edited End IBAction”中时不起作用,但知道为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!