IOS Proxy Transfer value (reverse pass)

Source: Internet
Author: User

Rest enough, should write something, a time ago cold, fever, tonsil inflammation, fever, tonsils again inflammation, again fever, enough, to enter the topic, this theme is through the agent to achieve the value, is the reverse transmission, is the inverse direction of the value (nonsense), the preparation work is, there are two controllers, There are two controls on each controller, one is button (used to implement the jump between the controller), one is a label (to show the value to be passed and the value passed), the proxy value is very practical, many times with the generation of understanding coupling, but the code is quite a lot;

Basic principle: There is a controller A, controller B, Agent C, when B is dying to find agent C, said: I am dying, you put me this legacy to a sent over, I have no chance, I entrust you to give this money to a, and then C Gallop, gave a. Formally because B can not do, so look for agent C,c said: Give me 100w, otherwise I will ...

I used the Viewcontroller (I'm lazy);

Viewcontoller.m

#import "ViewController.h" #import "AirViewController.h" @interface Viewcontroller () <airviewcontrollerdelegate >/** * Used to display values passed in/@property (nonatomic,weak) UILabel *textlabel; @end @implementation viewcontroller-(void)        viewdidload {[Super viewdidload]; [Self setupsubviews];}    -(void) setupsubviews{//Initialize a button UIButton *btn = [[UIButton alloc] initwithframe:cgrectmake (100, 100, 100, 100)];    Btn.backgroundcolor = [Uicolor Graycolor];    [btn settitle:@ "Next page" Forstate:uicontrolstatenormal];    [Btn addtarget:self Action: @selector (Btnclick) forcontrolevents:uicontroleventtouchupinside];        [Self.view ADDSUBVIEW:BTN]; The initialization display is passed over to the worthy label UILabel *textlabel = [[UILabel alloc] Initwithframe:cgrectmake (0, 4, self.view.bounds.size.width,    0)];    Textlabel.text = @ "no hairs";    Textlabel.textalignment = Nstextalignmentcenter;    Textlabel.backgroundcolor = [Uicolor Greencolor];    [Self.view Addsubview:textlabel]; Self.textlabel = Textlabel;} Click button Event-(void) btnclick{Airviewcontroller *NEXTVC = [[Airviewcontroller alloc] init];    Nextvc.delegate = self; [Self PRESENTVIEWCONTROLLER:NEXTVC animated:yes completion:nil];} Method of #pragma mark-#pragma mark-airviewcontrollerdelegate-(void) Airviewcontroller: (Airviewcontroller *) Controleller Andvalue: (NSString *) mystr{self.textLabel.text = mystr;} @end


As follows:


AirViewController.h

#import <UIKit/UIKit.h> @class airviewcontroller, @protocol airviewcontrollerdelegate <nsobject>/** *  Notification Value * *  @param controleller self *  @param mystr        The string to be passed, you can change the type */-(void) Airviewcontroller as required: ( Airviewcontroller *) Controleller andvalue: (NSString *) mystr; @end @interface airviewcontroller:uiviewcontroller/** *  Set Agent (note: must be weak) */@property (nonatomic,weak) id<airviewcontrollerdelegate> delegate; @end

Airviewcontroller.m

#import "AirViewController.h" @interface Airviewcontroller () @property (nonatomic,weak) UILabel *mylabel;@    End@implementation airviewcontroller-(void) viewdidload {[Super viewdidload];        Self.view.backgroundColor = [Uicolor Whitecolor]; [Self setupsubviews];} -(void) setupsubviews{//Return button, click the Back button to notify the mylabel above the string UIButton *backbtn = [[UIButton alloc] Initwithframe:cgrect    Make (100, 400, 100, 100)];    Backbtn.backgroundcolor = [Uicolor Graycolor];    [Backbtn settitle:@ "prev" forstate:uicontrolstatenormal];    [Backbtn addtarget:self Action: @selector (Backbtnclick) forcontrolevents:uicontroleventtouchupinside];        [Self.view ADDSUBVIEW:BACKBTN];    UILabel *textlabel = [[UILabel alloc] Initwithframe:cgrectmake (0, Self.view.bounds.size.width, 40)];    Textlabel.textalignment = Nstextalignmentcenter;    Textlabel.backgroundcolor = [Uicolor Greencolor];    Textlabel.text = @ "Welcome to my blog!";    [Self.view Addsubview:textlabel]; Self.mylabel = Textlabel;} -(void) backbtnclick{if ([Self.delegate respondstoselector: @selector (airviewcontroller:andvalue:)]) {[Self].    Delegate Airviewcontroller:self AndValue:self.myLabel.text]; } [self Dismissviewcontrolleranimated:yes completion:nil];} @end
As follows:



When I click on the "Previous page" button, a miracle appears, such as:


At this time, not @ Mao are not, but there is a high-end atmosphere of the upper class of English, which is the value of the agent transfer, can be any object;

if reproduced please specify the transfer to: Airzilong's Blog

IOS Proxy Transfer value (reverse pass)

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.