Question

I am trying to access the indexPath of my tableView from a method that doesn't declare NSIndexPath.

This is what I am trying to do:

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index {
    switch (index) {
        case 0:
        {

            NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];

            DetailScheduleViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];

            svc.title = [[news objectAtIndex:tempIndexPath.row]objectForKey:@"Series"];

            svc.newsArticle = [news objectAtIndex:tempIndexPath.row];

            [self.navigationController pushViewController:svc animated:YES];

            [cell hideUtilityButtonsAnimated:YES];
            break;
        }

        default:
            break;
    }
}

Of course, the issue here is this:

        NSIndexPath *tempIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];

The indexPathForRow is 0 and it will only return the first cell item. Thats not what I want. I want to be able to return the whole list in the indexPath. How can I do this?

  • Let me know if you guys need more clarification. Thanks!
Was it helpful?

Solution

You should ask the tableView for the indexPath like this:

- (void)swipeableTableViewCell:(SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex:(NSInteger)index
{
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top