gpt4 book ai didi

ios - 无法从 willDisplayCell 方法访问单元格

转载 作者:行者123 更新时间:2023-11-29 01:03:36 25 4
gpt4 key购买 nike

我有两种方法可以改变单元格的附件类型。第一个在所有单元格加载后调用,另一个在用户单击任何单元格时调用。

第二种方法工作正常,它从选定的单元格中删除复选标记。不幸的是,第一个什么都不做(我想在其中一个单元格中添加复选标记)。这让我很困惑,因为这些方法应该是一样的,不是吗?

// First method
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

if ([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows]
lastObject]).row)
{
LanguageTableViewCell *cell = [self.tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow:myNumber inSection:0]];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}

// Second method
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
LanguageTableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:myNumber inSection:0]];
cell.accessoryType = UITableViewCellAccessoryNone;
}

我尝试更改单元格类别,但仍然无法正常工作。我不确定第一个函数是否在正确的时间调用 = 在 vi​​ewDidLoad 之后...感谢您的帮助!

最佳答案

您想使用 - (__kindofUITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

关于ios - 无法从 willDisplayCell 方法访问单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36703745/

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