Myaaoonn
Myaaoonn

Reputation: 997

Index Path nested Tableview in IOS

I have a tableview which is inside a tableview cell. I need the main tableview index path in that sub tableview "cellForRowAtIndexPath" method . I am stuck on this point. My datasource and delegate methods are in same class.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Configure the cell...
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil && [tableView tag] == 200) {
    //main tableview
 }
else if(cell == nil && tableView.tag == 106)
{
  //sub tableview
   here I need the index path of main tableview
} 

}

How can I get the index path of main table view? enter image description here

Upvotes: 0

Views: 609

Answers (1)

Gaurav Patel
Gaurav Patel

Reputation: 957

Try This:

UITableViewCell *cell = (UITableViewCell *) tableView.superview.superview.superview;
UITableView *curTableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [curTableView indexPathForCell:cell];

Upvotes: 2

Related Questions