How to find indexPath for tapped accessory button in tableView

前端 未结 4 1693
独厮守ぢ
独厮守ぢ 2020-12-11 01:00

I\'ve simple UITableView with one section and few rows. When user clicks cell accessory button (which is connected with detailsSegue. I want to kno

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 02:04

    As you have discovered, the system sends you the prepareForSegue:sender: message before it sends you the tableview:accessoryButtonTappedForRowWithIndexPath: message.

    But, when it sends you the prepareForSegue:sender: message, the sender argument is the UITableViewCell containing the accessory view. You can use that to determine which row's accessory button was tapped:

    else if ([segue.identifier isEqualToString:@"detailsSegue"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
        Annotation *annotation = [self.viewsList objectAtIndex:indexPath.row];
        DetailsViewController *dvc = segue.destinationViewController;
        dvc.wikiKey = annotation.title;
    }
    

提交回复
热议问题