objective c - XCode 5.1.1 iOS 7.1 Send data to either previous controller -


this question has answer here:

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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -