objective c - prepareForSegue is not called after performSegue:withIdentifier: with popover style -
objective c - prepareForSegue is not called after performSegue:withIdentifier: with popover style -
i have universal app, sharing same controller ipad , iphone storyboard. have set uilongpressgesturerecognizer on uitableview, when cell pressed on iphone calls action perform segue:
-(ibaction)showdetail:(id)sender { uilongpressgesturerecognizer *gesture = (uilongpressgesturerecognizer*)sender; if (gesture.state == uigesturerecognizerstatebegan) { cgpoint p = [gesture locationinview:self.thetableview]; nsindexpath *indexpath = [self.thetableview indexpathforrowatpoint:p]; if (indexpath != nil) { [self performseguewithidentifier:segue_detail sender:indexpath]; } } }
the segue detail view performed 'push'. first thing should notice sender nsindexpath, way found passing selected cell. maybe there's improve solution. works fine, in sense segue performed, , before prepareforsegue called too.
however happens on ipad, have changed segue identifier popover. things working in part, segue performed, prepareforsegue not called , hence destination view controller not set should be.
what doing wrong ?
what have discovered far, segue identifier not popover these invocations made ios:
prepareforsegue (on source controller) viewdidload (on destination controller)while in popover segue invocation order is:
viewdidload (on destination controller) prepareforsegue (on source controller)just because set logic in viewdidload, controller not initialized, , crash happened. not true prepareforsegue not called, truth getting exception, , wrongly mistaken prepareforsegue not getting called.
i couldn't set in viewwillappear because phone call coredata had made , didn't want check if entities ok each time view display.
how did solve ? created method in destination controller
-(void)prepareviewcontroller { // initialization logic... }
and changing prepareforsegue method in source controller itself:
-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { myviewcontroller *mvc = (myviewcontroller*)[segue destinationviewcontroller]; // passing variable // segue style other popover called first viewdidload mvc.myprop1=@"prop1"; mvc.myprop2=@"prop2"; // viewwillappear not yet called // sending message controller // view initialized [mvc prepareviewcontroller]; }
don't know if expected behavior popover, anyway things working.
objective-c ipad xcode4 storyboard uipopovercontroller
Comments
Post a Comment