objective c - XCode 5.1.1 iOS 7.1 Send data to either previous controller -
this question has answer here:
- passing data between view controllers 35 answers
i have 2 view controllers, , b. when click button, these take me c - table view it's own view controller. c has list of items when click 1 takes previous controller. using code go in didselectrowatindexpath:
[self.navigationcontroller popviewcontrolleranimated:no]; my problem is: how send data programmatically either or b once i've popped c?
i've looked around function prepareforsegue doesn't called on pop - i've used nslog , nothing printed when going back.
you have create custom delegate
in cviewcontroller.h
@protocol secondviewcontrollerdelegate <nsobject> @required - (void)datafromcontroller:(nsstring *)data; @end @interface cviewcontroller : uiviewcontroller @property (nonatomic, weak) id<secondviewcontrollerdelegate> delegate; @end in cviewcontroller.m
- (ibaction)btnbackaction:(id)sender { if([_delegate respondstoselector:@selector(datafromcontroller:)]) { [_delegate datafromcontroller:@"data received"]; } [self.navigationcontroller popviewcontrolleranimated:yes]; } in or bviewcontroller (where want come c)
// not forget import cviewcontroller.h @interface or bviewcontroller : uiviewcontroller<secondviewcontrollerdelegate> now in or bviewcontroller.m
// when go cviewcontroller oor b have pass delegate cview.delegate = self; - (void)datafromcontroller:(nsstring *)data { // method invokes when come cviewcontroller uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(50, 50, 250, 50)]; label.autoresizingmask = uiviewautoresizingflexibleheight|uiviewautoresizingflexiblewidth| uiviewautoresizingflexiblebottommargin; label.textalignment = nstextalignmentcenter; label.text = [nsstring stringwithformat:@"your data: %@", data]; [self.view addsubview:label]; }
Comments
Post a Comment