ios - Unable to segue using an accessory indicator -


i have segue 3 transitions (see code below). first button. works perfectly. second tapping on cell in table view. 1 works too. third accessory button in tableview cell. 1 opens proper view controller, not pass reference patient have coded. have verified nslog statement in viewdidload of new view controller , shows patient being null.

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {      if ([[segue identifier] isequaltostring:@"addpatient"]) {          // add new patient (selection segue)          uinavigationcontroller *navigationcontroller = segue.destinationviewcontroller;          rxaddpatientviewcontroller *addpatientviewcontroller = (rxaddpatientviewcontroller*)navigationcontroller.topviewcontroller;          patient *addpatient = [nsentitydescription insertnewobjectforentityforname:@"patient" inmanagedobjectcontext:[self managedobjectcontext]];          addpatientviewcontroller.addpatient = addpatient;     }      if ([[segue identifier] isequaltostring:@"toprescriptions"]) {          // view prescriptions selected patient (selection segue)          rxprescriptionsviewcontroller *prescriptionviewcontroller = [segue destinationviewcontroller];          nsindexpath *indexpath = [self.tableview indexpathforselectedrow];          patient *selectedpatient = (patient*) [self.fetchedresultscontroller objectatindexpath:indexpath];          prescriptionviewcontroller.selectedpatient = selectedpatient;          nslog(@"selected patient %@", selectedpatient.patientfirstname);      }      if ([[segue identifier] isequaltostring:@"editpatient"]) {          // edit selected patient (accessory action)          uinavigationcontroller *navigationcontroller = segue.destinationviewcontroller;          rxeditpatientviewcontroller *editpatientviewcontroller = (rxeditpatientviewcontroller*)navigationcontroller.topviewcontroller;          nsindexpath *indexpath = [self.tableview indexpathforselectedrow];          patient *editpatient = (patient*) [self.fetchedresultscontroller objectatindexpath:indexpath];          // passing reference editpatientviewcontroller         editpatientviewcontroller.editpatient = editpatient;          nslog(@"selected patient %@", editpatient.patientfirstname);     } } 

the indexpathforselectedrow null when click on accessory button because you're not selecting row. however, sender argument in prepareforsegue:sender: cell accessory button contained in. so, should use following method indexpath (notice changed typing of argument uitableviewcell id):

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(uitableviewcell *)sender {       if ([[segue identifier] isequaltostring:@"editpatient"]) {          // edit selected patient (accessory action)          uinavigationcontroller *navigationcontroller = segue.destinationviewcontroller;          rxeditpatientviewcontroller *editpatientviewcontroller = (rxeditpatientviewcontroller*)navigationcontroller.topviewcontroller;          nsindexpath *indexpath = [self.tableview indexpathforcell:sender];          patient *editpatient = (patient*) [self.fetchedresultscontroller objectatindexpath:indexpath];          // passing reference editpatientviewcontroller         editpatientviewcontroller.editpatient = editpatient;          nslog(@"selected patient %@", editpatient.patientfirstname); } 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -