Application scenario: Sometimes from interface a jump to interface B, interface B in return to the need to pass the results of processing to a.
Implementation ideas: 1, define a responsible for the value of the covariance, interface A has the semantic attributes, and implement the method of the covariance
2, Interface B also has this semantic attribute (the proxy requires both have a reference to the same object), then gets the reference pointer of interface A when it returns, and specifies that the calling target of the "B" is a, calling the method of value in the covariance.
Specific code:
A's header file:
#import <UIKit/UIKit.h>
@protocol passvaluedelegate <nsobject>
-(void) SetValue: (nsstring *) param;
@end
@interface Viewcontroller: Uiviewcontroller
@propertyID<passvaluedelegate> passvaluedelegate;
@end
Implementation file for a:
#import "ViewController.h"
#import "ViewController2.h"
@interfaceviewcontroller ()
{
}
@end
@implementation Viewcontroller
-(void) viewdidload
{
[superviewdidload];
Additional setup after loading the view, typically from a nib.
UIButton *btn =[UIButtonbuttonwithtype:uibuttontyperoundedrect];
Btn. frame=CGRectMake(+,+, +);
[btn settitle: @ "btn" Forstate: uicontrolstatenormal";
[btn addtarget: self Action: @selector (BTN) forcontrolevents: uicontroleventtouchupinside";
[self. Viewaddsubview: btn];
self. View. BackgroundColor=[uicolorredcolor];
}
-(void) SetValue: (NSString *) param{
NSLog (@ "Pass value is:%@", param);
}
-(void) btn
{
[self. Navigationcontroller pushviewcontroller:[[viewcontroller2 Alloc]init] Animated:YES];
}
-(void) didreceivememorywarning
{
[Super didreceivememorywarning];
//Dispose of any resources, can be recreated.
}
@end
B's header file:
#import <UIKit/UIKit.h>
@interface ViewController2:Uiviewcontroller
@end
Implementation file of B:
#import "ViewController2.h"
#import "ViewController.h"
@interfaceViewController2 ()
@property ID<passvaluedelegate> passvaluedelegate;
@end
@implementation ViewController2
-(void) viewdidload
{
[superviewdidload];
UIButton *btn =[UIButtonbuttonwithtype:uibuttontyperoundedrect];
Btn. frame=CGRectMake(+,+, +);
[btn settitle:@ "Back"forstate:uicontrolstatenormal];
[btn addTarget:self action:@selector(BTN) forControlEvents:uicontroleventtouchupinside];
[self. Viewaddsubview: btn];
}
-(void) btn
{
//NSLog (@ "%@", Self.navigationcontroller.childviewcontrollers[0]);
self Passvaluedelegate= self Navigationcontroller Childviewcontrollers[ 0 ];
[self. Navigationcontrollerpoptorootviewcontrolleranimated:YES];
[self. PassvaluedelegatesetValue:@ "123456789"];
}
-(void) didreceivememorywarning
{
[superdidreceivememorywarning];
//Dispose of any resources, can be recreated.
}
@end