A
A
Artem_AK2015-04-14 08:36:22
Objective-C
Artem_AK, 2015-04-14 08:36:22

How to get the index of the pressed accessory button?

The problem is that the method in which you can get the index of the pressed accessory button

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{}

works out after
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {}

And I plan to use this index in prepareForSegue.
How to get the index of the pressed accessory button before the prepareForSegue method is processed?
Thank you!
UPD
Solution:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"details" sender:indexPath];

}

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"workout"]) {
        
        UITableViewCell *cell = (UITableViewCell*)sender;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
        
        WorkoutTVC *wvc = (WorkoutTVC *) segue.destinationViewController;
        wvc.workoutName = [self.listOfWorkoutNames objectAtIndex:indexPath.row];
    }
    else if ([segue.identifier isEqualToString:@"details"]) {
        
        NSIndexPath *indexPath = [sender isKindOfClass:[NSIndexPath class]] ? (NSIndexPath*)sender : [self.tableView indexPathForSelectedRow];
        
        WorkoutDetailsVC *wdvc = (WorkoutDetailsVC *) segue.destinationViewController;
        wdvc.workoutName = [self.listOfWorkoutNames objectAtIndex:indexPath.row];
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
An, 2015-04-15
@Artem_AK

I don't quite understand what you are doing. Ideally, attach an example project with a demonstration of the problem to the question.
But the following should help you - in the method
"Save" indexPath and manually call
*This is only if the UITableView delegate is a UIViewController, and you probably have it)
And of course, you need to remove the previous performSegue, explicit , or the one that you clung to InterfaceBuilder'e

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question