把它当编辑真的结束IBAction为UITableView的reloadData不能正常工作,btt

2019-10-19 09:47发布

我把文本框在表中的每一个细胞。 和编辑文本字段后,一个EditingDidEnd事件将触发。 在hanlding这一事件的方法我尝试使用

[XXXUITableViewController.tableView reloadData];

但它不工作(委托方法不叫)。

如果我尝试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.)
    }

Answer 1:

在这里,在这种方法,因为保存新的数据你不重装新的数据,使其只显示旧数据后,也刷新你的阵列,在表视图显示。

- (IBAction)nameChange:(id)sender {

        [self savedata];
        [yourArray removeAllObjects];
        //then here put new that in yourArray
        [self.tableView reloadData];//(not working)
    }

编辑:

也调用此方法[self.tableView reloadData]; 在你的最后一行savedata方法。



Answer 2:

每次创建单元格时,必须指定一个代表文本字段,是它。 如果您使用的是动态表中添加以下代码cell.yourTextField.delegate = self这个方法- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

或者,也许你忘了你的订阅类的协议?

在任何情况下,方法reloadData更新其数据源表中的数据,我不明白你为什么需要你在一个领域是在表中输入文本后调用此方法。 如果你不救这个文本,它会调用后消失reloadData方法。



文章来源: UITableView reloadData not working when put it in Editing Did End IBAction, btter know why