android
android

Reputation: 473

How to get IndexPath first section tableview of subcell using Objective C?

I am trying to create accordion tableview. here I can get easily parent tableview selected cell index path values but I cant get subtable (Expandable child tableview cell) row index path. Please give me any solution for my issue and find below code

My Code :

// @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
        // ...

    }
}

I am checking by open source code : https://github.com/ajkoshy7/SubTable

Upvotes: 0

Views: 1170

Answers (1)

Irfan
Irfan

Reputation: 5130

Get indexpath of selected Child from childIndex:

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

Upvotes: 1

Related Questions