IOS Proxy Protocol Transfer value

Source: Internet
Author: User

Jump from Viewcontroller to Firstviewcontroller, send a Nsinteger value back in firstviewcontroller


Viewcontroller.m

#import "ViewController.h"

#import "FirstViewController.h"


@interface viewcontroller () <passvaluedelegate>

@end


@implementation Viewcontroller


-(void) Viewdidload {

[superviewdidload];

Additional setup after loading the view, typically from a nib.

self. View. BackgroundColor = [uicolorwhitecolor];

_mybutton = [UIButtonbuttonwithtype: Uibuttontypecustom];

_mybutton. frame =cgrectmake(+,-- );

[_mybuttonsettitle:@ "Jump"forstate: UIControlStateNormal];

    _mybutton Backgroundcolor = [ uicolor redcolor ];

[_mybuttonaddTarget:self action:@selector (clicked:)forcontrolevents:uicontroleventtouchupinside];

[Self. View addsubview:_mybutton];

}

button click event to jump to Firstviewcontroller

-(void) clicked: (UIButton *) button

{

firstviewcontroller *firvc = [[firstviewcontrolleralloc] Init ];

FIRVC. passdelegate =self;

[self presentviewcontroller: firvc animated:YES Completion:nil];

}


-(void) SetValue: (nsinteger ) value

{

NSLog (@ "value =====%ld", (long) value);

}


@end







FirstViewController.h

Protocol and method (the type of the value to be passed by the name itself)

@protocol Passvaluedelegate <nsobject>

-(void) SetValue: ( Nsinteger ) value;

@end


@interface Firstviewcontroller: Uiviewcontroller

Check Agent Properties

@property ( nonatomic ,   assign id < Passvaluedelegate > passdelegate;

@property (nonatomic, assign)Nsinteger number ;

@end



Firstviewcontroller.m

#import"FirstViewController.h"


@interface firstviewcontroller ()


@end


@implementation Firstviewcontroller


-(void) Viewdidload {

[superviewdidload];

Additional setup after loading the view.

self. View. BackgroundColor = [uicolorgreencolor];

_mybutton = [UIButtonbuttonwithtype:uibuttontypecustom ];

_mybutton. frame =cgrectmake(+,-- );

      [ _mybutton addtarget : self Action : @selector (clicked:) forcontrolevents : uicontroleventtouchupinside

[Self. View addsubview:_mybutton];


_number = +;

}


Methods of Proxy Compliance protocol

-(void) clicked: (UIButton *) button

{

< Span style= "Color:rgb (0,0,0)" >    [ self passdelegate setvalue : ];

[self dismissviewcontrolleranimated:YEScompletion: Nil];

}



IOS Proxy Protocol Transfer 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.