I am attempting to use a storyboard/segue to handle the transition between a UITableView with both standard transition as well as detail disclosure button. Having read a few different posts on here I have set up my project this way:
Implement accessoryButtonTappedForRowWithIndexPath
as follows:
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"DetailSegue" sender:self];
}
This works great and my prepareForSegue: sender:
gets called as expected. The trouble is, I need to know the indexPath for the element selected. The segue from the UITableViewCell retrieves the indexPath like this:
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Unfortunately when I try to do that having called the accessoryButton, that returns null
.
The original question I am basing some of this code off of is here: Detail Disclosure Button and Segues
Is there a method of the tableView which returns indexPath for accessoryButtons? Do I need to access the indexPath in some other manner?
You don't have to override accessoryButtonTappedForRowWithIndexPath
.
In prepareForSegue
, when working with a detail disclosure button, instead of:
[self.tableView indexPathForSelectedRow]
use:
[self.tableView indexPathForCell:sender]
The sender is already the detail disclosure button's cell.
The sender
argument is, according to the documentation:
The object that you want to use to initiate the segue. This object is made available for informational purposes during the actual segue.
I don't see any reason why you can't use the index path as the sender instead of self
, then access the index path in prepareForSegue:
.
If that doesn't work, store the index path in an ivar and access that in prepareForSegue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With