Monday, 15 June 2015

objective c - Trouble getting delegate working in ios -



objective c - Trouble getting delegate working in ios -

i'm starting larn objective-c , i'm not 100% on syntax yet, , think might i'm having trouble, 1 time again i'm not sure. i'm trying 1 view controller send message parent/callee view controller. have set this:

//parentviewcontroller.h #import "subviewcontroller.h" @interface parentviewcontroller : uiviewcontroller <subviewcontrollerdelegate> - (void) sendmessagetoparent:(nsinteger)num; @end

this implementation:

//parentviewcontroller.m @implementation parentviewcontroller - (void) sendmessagetoparent:(nsinteger)num { nslog(@"message %d", num); } - (void) buttonpushed { [self performseguewithidentifier:@"subview" sender:sender]; } @end

here's other view controller setup:

//subviewcontroller.h @protocol subviewcontrollerdelegate <nsobject> - (void) sendmessagetoparent:(nsinteger)num; @end @interface subviewcontroller : uiviewcontroller @property (nonatomic, weak) id <subviewcontroller> delegate; @end

and implementation:

//subviewcontroller.m @implementation subviewcontroller @synthesize delegate; - (void) { [self.delegate sendmessagetoparent:4]; [self.dismissviewcontrolleranimated:yes completion:nil]; }

appreciate help, thanks.

you need add together parentviewcontroller:

- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([[segue identifier] isequaltostring:@"subview"]) { subviewcontroller *vc = [segue destinationviewcontroller]; vc.delegate = self; } }

ios objective-c

No comments:

Post a Comment