ios - Object assigned to property of target view controller in prepareForSegue comes out as a UITableViewCell -
i trying set property of view controller i'm segueing to custom object (restroom
), it's coming out uitableviewcell
.
here code origin view controller triggering segue. userdidselectrestroomnotification
method called when user selects cell in table view lists restrooms - application supposed segue view controller lists details of restroom:
- (void)userdidselectrestroomnotification:(nsnotification *)notification { restroom *selectedrestroom = (restroom *)[notification object]; [self performseguewithidentifier:@"showrestroomdetails" sender:selectedrestroom]; }; - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([segue.identifier isequaltostring:@"showrestroomdetails"]) { restroomdetailsviewcontroller *restroomdetailsviewcontroller = (restroomdetailsviewcontroller*)segue.destinationviewcontroller; restroomdetailsviewcontroller.restroom = sender; } }
here code in info source notification posed:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // post notification when selection made nsnotification *notification = [nsnotification notificationwithname:rrtableviewdidselectrestroomnotification object:[self restroomforindexpath:indexpath]]; [[nsnotificationcenter defaultcenter] postnotification:notification]; } - (restroom *)restroomforindexpath:(nsindexpath *)indexpath { homecoming [self.restroomslist objectatindex:[indexpath row]]; }
point being, sending along restroom
object in notification.
the issues comes when in restroomdetailsviewcontroller
, trying set text of label name of restroom
object i'm passing along:
@interface restroomdetailsviewcontroller () @property (weak, nonatomic) iboutlet uilabel *namelabel; @end @implementation restroomdetailsviewcontroller - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; self.namelabel.text = self.restroom.name; } @end
it crashes @ self.namelabel.text = self.restroom.name
. when inspect objects, see self.restroom
object uitableviewcell
. confuses me farther that uitableviewcell
appears cell selected user trigger segue -- i.e. 1 set in info source:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsparameterassert([indexpath section] == 0); nsparameterassert([indexpath row] < [_restroomslist count]); uitableviewcell *restroomcell = [tableview dequeuereusablecellwithidentifier:restroomcellreuseidentifier]; if(!restroomcell) { restroomcell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:restroomcellreuseidentifier]; } restroomcell.textlabel.text = [[_restroomslist objectatindex:[indexpath row]] name]; homecoming restroomcell; }
i'm not understanding why happens , how restroom
property assigned restroom
object.
why using postnotification ?
i don't see requirement here utilize notification. simple function parameter work.
try next way phone call segue
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { [self performseguewithidentifier:@"showrestroomdetails" sender:[self restroomforindexpath:indexpath]]; } - (restroom *)restroomforindexpath:(nsindexpath *)indexpath { homecoming [self.restroomslist objectatindex:[indexpath row]]; } - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { restroom *selectedrestroom = (restroom *)sender; if ([segue.identifier isequaltostring:@"showrestroomdetails"]) { restroomdetailsviewcontroller *restroomdetailsviewcontroller = (restroomdetailsviewcontroller*)segue.destinationviewcontroller; restroomdetailsviewcontroller.restroom = selectedrestroom ; } }
ios objective-c uitableview
No comments:
Post a Comment