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