1789040
1789040

Reputation: 579

indexPath.row returns properly with didSelectRow, but not with accessoryButtonTapped?

Here is my code:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"editInfo" sender:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"editInfo"]) {
        EditInfoViewController *vc = [segue destinationViewController];
        NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
        NSLog(@"%d",selectedIndex);
        [vc setSelectedIndex:selectedIndex];
    }
    else if ([[segue identifier] isEqualToString:@"sendMessage"]) {
                 ...
    }
}

The selectedIndex variable is always NSLogged as 0... Any suggestions? Thanks.

Upvotes: 1

Views: 205

Answers (1)

John Sauer
John Sauer

Reputation: 4421

Tapping a UITableViewCell's accessoryButton doesn't select the row containing the accessoryButton.

When you call performSegueWithIdentifier, you could pass indexPath as the sender, which you could then reference in prepareForSegue.

Upvotes: 4

Related Questions