ios - protocol method is not being called by the delegate -
i have implemented protocol in app,
i have declared protocol method in loginviewcontroller
, calling protocolmethod
confirmviewcontroller
here code snippet: loginviewcontroller.h
@protocol firstcontrollerdelegate<nsobject> @required -(void)protocolmethod; @end @interface loginviewcontroller : uiviewcontroller<firstcontrollerdelegate> @end
loginviewcontroller.m
- (ibaction)loginbtnclicked:(id)sender { confirmviewcontroller *obj = [confirmviewcontroller new]; obj.delegate=self; [self performseguewithidentifier:@"confirmloginsegue" sender:self]; } -(void)protocolmethod{ nslog(@"--- not callled ---"); [self dismissviewcontrolleranimated:no completion:nil]; }
code confirmviewcontroller.h
@interface confirmviewcontroller : uiviewcontroller @property (nonatomic, assign) id <firstcontrollerdelegate> delegate; @end
confirmviewcontroller.m
(ibaction)continueclicked:(id)sender { [_delegate protocolmethod]; //calling protocol method... [self dismissviewcontrolleranimated:yes completion:nil]; }
where doing mistake?
please , in advance!
wrong approach , delegate initialisation
in lines:-
confirmviewcontroller *obj = [confirmviewcontroller new]; obj.delegate=self; [self performseguewithidentifier:@"confirmloginsegue" sender:self]; --- loosing object here
solution
in attribute inspector give identifier confirmviewcontroller, push vc , set delegate object confirmviewcontroller this:-
uistoryboard *storyboard = [uistoryboard storyboardwithname:@"mainstoryboard" bundle:nil]; confirmviewcontroller *confirmviewcontroller = [storyboard instantiateviewcontrollerwithidentifier:@"confirmviewcontroller"]; confirmviewcontroller.delegate=self; [self.navigationcontroller pushviewcontroller:confirmviewcontroller animated:yes];
Comments
Post a Comment