As with the notification is also two controllers, then the code creates the control directly on the code
#import "ViewController.h"
#import "TwoViewController.h"
@interface Viewcontroller ()
{
UIButton *_nextbtn;
UILabel *_showlabel;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
[Self show];
}
-(void) show{
_NEXTBTN = [[UIButton alloc]initwithframe:cgrectmake (100, 100, 100, 100)];
[_nextbtn Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal];
[_nextbtn settitle:@ "Next" forstate:uicontrolstatenormal];
[_nextbtn addtarget:self Action: @selector (Nextbtnclick:) forcontrolevents:uicontroleventtouchupinside];
[Self.view ADDSUBVIEW:_NEXTBTN];
_showlabel = [[UILabel alloc]initwithframe:cgrectmake (100, 300, 100,50)];
[_showlabel Setbackgroundcolor:[uicolor Greencolor];
[_showlabel Settextcolor:[uicolor Redcolor];
[Self.view Addsubview:_showlabel];
}
-(void) Nextbtnclick: (UIButton *) nextbtnclick{
Twoviewcontroller * = [[Twoviewcontroller alloc]init];
Two.block = ^ (NSString * str) {
_showlabel.text = str;
};
[Self presentviewcontroller:two animated:yes completion:nil];
}
In the TwoViewController.h
#import <UIKit/UIKit.h>
typedef void (^myblock) (NSString *);
@interface Twoviewcontroller:uiviewcontroller
@property (nonatomic,copy) Myblock block;
@end
in the TWOVIEWCONTROLLER.M
#import "TwoViewController.h"
@interface Twoviewcontroller ()
{
UIButton *_backbtn;
Uitextfield *_textfield;
}
@end
@implementation Twoviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.view.backgroundColor = [Uicolor Bluecolor];
[Self Shoulabel];
}
-(void) shoulabel{
_BACKBTN = [[UIButton alloc]initwithframe:cgrectmake (100, 100, 100, 100)];
_backbtn.backgroundcolor = [Uicolor Redcolor];
[_backbtn settitle:@ "Shang" forstate:uicontrolstatenormal];
[_backbtn addtarget:self Action: @selector (Shangbtnclick:) forcontrolevents:uicontroleventtouchupinside];
[Self.view ADDSUBVIEW:_BACKBTN];
_textfield = [[Uitextfield alloc]initwithframe:cgrectmake (100, 400, 250, 35)];
_textfield.backgroundcolor = [Uicolor Yellowcolor];
[Self.view addsubview: _textfield];
}
-(void) Shangbtnclick: (UIButton *) shangbtn{
[Self Dismissviewcontrolleranimated:yes completion:^{
if (Self.block) {
Self.block (_textfield.text);
}
}];
}
This makes it simple to pass the value
IOS uses block for counter-pass values