gpt4 book ai didi

ios - 首次显示后更改 UITableView 删除按钮文本(在编辑模式下)

转载 作者:行者123 更新时间:2023-12-01 16:47:37 25 4
gpt4 key购买 nike

一旦编辑模式开始,我想更改 UITableView 显示的删除文本。

委托(delegate)方法:

 -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath 

仅当第一次显示索引路径处的 deleteButton 时才调用,但如果我的模型在它下面发生更改,我需要更新此文本。是否可以在不重新加载整个部分的情况下再次调用此方法?请参阅下面的代码,并提前感谢您的帮助。
    -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
ContainerTableViewCell *cell = (ContainerTableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];

if ([cell.editPhotos count] > 0) {
return [NSString stringWithFormat:@"Delete %d photos", [cell.editPhotos count]];
}
else{
return @"Delete Section";
}
}

在某些上下文中,我有一个嵌套在uiatevieviewcell中的UicollectionView,选择单元格时将发送通知。我尝试使用以下内容重新加载该部分:
 [self.tableView reloadRowsAtIndexPaths:@[[self.tableView indexPathForCell:cell]] withRowAnimation:UITableViewRowAnimationNone];

但这是不可取的,因为它会导致 tableview 跳转并且无法正确显示选择。我也试过:
 [self.tableView.delegate tableView:self.tableView titleForDeleteConfirmationButtonForRowAtIndexPath:[self.tableView indexPathForCell:cell]];

绝望中。虽然这确实会导致调用正确的方法,但它不会更改删除文本。

最佳答案

我刚刚编写了一个基本的测试应用程序,它可以按预期工作。

我认为也许你获取数据的方式不是最好的方法。您正在查询一个可能已出队的单元格,因此可能不包含最新信息。

相反,您应该努力实现真正的 MVC 模式,其中您的数据独立于您的 View ,包括 Collection View 单元格。

关于ios - 首次显示后更改 UITableView 删除按钮文本(在编辑模式下),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18686653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com