ios - Passing indexpath to performsequewithidentifier from uitablerowaction button -


here delegate method:

-(nsarray *)tableview:(uitableview *)tableview editactionsforrowatindexpath:(nsindexpath     *)indexpath { uitableviewrowaction *button = [                                 uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledefault title:@"more" handler:^(uitableviewrowaction *action, nsindexpath *indexpath) {     [self performseguewithidentifier:@"areadescriptionsegue" sender:indexpath];     nslog(@"more button tapped"); }                                 ]; button.backgroundcolor = [uicolor graycolor]; //arbitrary color return @[button]; //array buttons want. 1,2,3, etc... } 

and here prepareforsegue:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([[segue identifier] isequaltostring:@"areadescriptionsegue"]) {     nslog(@"segue areas screen");     nsindexpath *newindexpath = [self.listtableview indexpathforcell:sender];     areadescriptioncontroller *vc = (areadescriptioncontroller*)[segue destinationviewcontroller];     vc.area = _feeditems[newindexpath.row];  } } 

the object passed destinationviewcontroller first object item , not @ correct indexpath.

can help, please?

you passed indexpath sender (in performsegue), there's no need indexpath line (in fact won't work since "sender" not cell),

nsindexpath *newindexpath = [self.listtableview indexpathforcell:sender] 

you should this,

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(nsindexpath *)sender {     if ([[segue identifier] isequaltostring:@"areadescriptionsegue"]) {         nslog(@"segue areas screen");         areadescriptioncontroller *vc = (areadescriptioncontroller*)[segue destinationviewcontroller];         vc.area = _feeditems[sender.row];      } } 

the reason got first row, newindexpath nil, , newindexpath.row evaluates 0.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -