gpt4 book ai didi

ios - 如何使用 Objective C 获取子单元格的 IndexPath 第一节表格 View ?

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

我正在尝试创建 Accordion tableview。在这里我可以很容易地得到 parent tableview selected cell index path values 但我不能得到 subtable (Expandable child tableview cell) row index path。请为我的问题提供任何解决方案并找到以下代码

我的代码:

// @optional
- (void)didSelectRowAtChildIndex:(NSInteger)childIndex underParentIndex:(NSInteger)parentIndex {

NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[self rowForParentIndex:parentIndex] inSection:0];
UITableViewCell *selectedCell = [self cellForRowAtIndexPath:indexPath];

if ([selectedCell isKindOfClass:[ParentTableViewCell class]]) {

//ParentTableViewCell * pCell = (ParentTableViewCell *)selectedCell;

// Insert code here to detect and handle child cell selection
// ...

}
}

我正在通过开源代码进行检查:https://github.com/ajkoshy7/SubTable

最佳答案

从 childIndex 中获取所选 Child 的索引路径:

NSIndexPath * indexPath = [NSIndexPath indexPathForRow:[self rowForParentIndex:parentIndex] inSection:0];
NSIndexPath * indexPathChild = [NSIndexPath indexPathForRow:[self rowForParentIndex:childIndex] inSection:indexPath.row];

关于ios - 如何使用 Objective C 获取子单元格的 IndexPath 第一节表格 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34155311/

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