I have a problem with the UItableViewCell accessory button.
My accessory button is “connected” with a segue to another UIViewController.
When I tap on an accessory button, I get the object from the model and I “pass” this object to the segue destinationViewController.
This is my prepare for segue method:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"IdentityCard"])
{
NSLog(@"%i" ,self.tableView.indexPathForSelectedRow.row);
[segue.destinationViewController showIdentityCardForTeacher:[self.teachers getTeacherInPosition:self.tableView.indexPathForSelectedRow.row]];
}
}
The problem is that the NSLog at the beginning of the method (after the “if”) show always the number 0!
I tried to implement the method:
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
but the prepare for segue method is executed before this method, so I can’t set any @property for “save” the indexPath.
How can I solve this problem?
I fix the problem in this way:
I connected the UIViewController to the destinationViewController (NOT FROM THE ACCESSORY BUTTON BUT FROM THE UIViewController).
I created a @property in the first View Controller:
then I modified the code like this:
Now it works!