#import <UIKit/UIKit.h> #import "SubViewController.h" @interface viewcontroller:uiviewcontroller< Subviewcontrollerdelegate> @end
#import "ViewController.h" @interface Viewcontroller () {Subviewcontroller *_subviewcontroller;} @end @implementation viewcontroller-(void) viewdidload {[Super viewdidload]; _subviewcontroller = [[Subviewcontroller alloc]init]; Self.view.backgroundColor = [Uicolor Orangecolor]; _subviewcontroller.delegate = self; UIButton *btn = [UIButton buttonwithtype:uibuttontypecustom]; Btn.frame = CGRectMake (10, 30,200, 30); [Btn settitle:@ "Jump to Subviewcontroller" forstate:uicontrolstatenormal]; [btn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal]; [Btn addtarget:self Action: @selector (Btnclick) forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:BTN]; UIButton *btn1 = [UIButton Buttonwithtype:uibuttontypesystem]; Btn1.frame = CGRectMake (10, 100, 200, 30); [Btn1 settitle:@ "Let Subviewcontroller discoloration" forstate:uicontrolstatenormal]; [Btn1 Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal]; [BTN1 Addtarget:self Action: @selector (Btn1click) forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:BTN1]; Do any additional setup after loading the view, typically from a nib.} -(void) btn1click{_subviewcontroller.view.backgroundcolor = [Uicolor redcolor];} -(void) btnclick{[self Presentviewcontroller:_subviewcontroller animated:yes completion:^{}];} -(void) changecoloer{self.view.backgroundColor = [Uicolor purplecolor];} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
#import <UIKit/UIKit.h> @protocol subviewcontrollerdelegate <nsobject>-(void) changecoloer;@ End@interface Subviewcontroller:uiviewcontroller@property (nonatomic,weak) __weak id<SubViewControllerDelegate >delegate; @end
#import <UIKit/UIKit.h> @protocol subviewcontrollerdelegate <nsobject>-(void) changecoloer;@ End@interface Subviewcontroller:uiviewcontroller@property (nonatomic,weak) __weak id<SubViewControllerDelegate >delegate; @end
In this little demo I built two view controllers, one is Viewcontroller and the other is Subviewcontroller.
Two pages to jump from one to the other
Click on the Subviewcontroller button to change the color in the Viewcontroller
Clicking the color Change button in Viewcontroller also changes the colors in the Subview
Agent essence is the transfer of pointers
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Use of iOS proxy, forward value, reverse pass value