bhavya kothari bhavya kothari - 3 months ago 37
iOS Question

indexpath row not getting in prepare for segue for detail disclosure

if([segue.identifier isEqualToString:@"Edit"]){

AddCoffeeViewController *avc = [segue destinationViewController];

Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:arow];
NSLog(@"ViewController.m prepareForSegue: arow: %d coffeeName:%@ price:%@ coffeeID:%d",arow,coffeeObj.coffeeName,coffeeObj.price,coffeeObj.coffeeID);
[coffeeObj setIsInEditMode:YES];
avc.EditCoffeeObj = coffeeObj;


I am not getting the correct row when i am pressing accessory button.

Although in below method i am getting the correct row.
Is there any way that i can get correct row prepare for segue if i do not want to use any ivar.

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

arow = indexPath.row;


enter image description here

tableViewCell accessory button: Performing modal segue(Edit)

+ Button (Navigation bar button Item): Performing modal segue(Add)


If you have hooked up accessory action in your storyboard then the sender in prepareForSegue:sender: will be the cell that that was tapped. This means you can just do something like

NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];