Use of iOS proxy, forward value, reverse pass value

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.