Create two controllers directly, click to jump to the second interface, then click on the button to pass the value
#import "ViewController.h"
#import "TWOOViewController.h"
@interface Viewcontroller ()
@property (nonatomic,weak) UILabel * label;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
UIButton * nextbtn = [[UIButton alloc]initwithframe:cgrectmake (0, Self.view.bounds.size.width, 50)];
Nextbtn.backgroundcolor = [Uicolor Redcolor];
[Nextbtn addtarget:self Action: @selector (Nextbtnclick:) forcontrolevents:uicontroleventtouchupinside];
[Nextbtn settitle:@ "Next Interface" forstate:uicontrolstatenormal];
[Self.view ADDSUBVIEW:NEXTBTN];
UILabel * LabelText = [[UILabel alloc]initwithframe:cgrectmake (0, Self.view.bounds.size.width, 50)];
Labeltext.backgroundcolor = [Uicolor Yellowcolor];
Labeltext.textcolor = [Uicolor Greencolor];
[Self.view Addsubview:labeltext];
Self.label = LabelText;
Create a notification
[[Nsnotificationcenter defaultcenter]addobserver:self selector: @selector (Nexttow:) name:@ "Nextbtnaa" object:nil];
}
-(void) Nextbtnclick: (uibutton*) nextbtn{
Twooviewcontroller * = [[Twooviewcontroller alloc]init];
[Self presentviewcontroller:two animated:yes completion:nil];
}
-(void) Nexttow: (nsnotification*) nontification{
Self.label.text = Nontification.object;
}
A second controller
#import "TWOOViewController.h"
@interface Twooviewcontroller ()
@end
@implementation Twooviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.view.backgroundColor = [Uicolor Bluecolor];
UIButton * backbtn = [[UIButton alloc]initwithframe:cgrectmake (0, Self.view.bounds.size.width, 50)];
[Backbtn settitle:@ "Back" forstate:uicontrolstatenormal];
[Backbtn addtarget:self Action: @selector (Backbtnclick:) forcontrolevents:uicontroleventtouchupinside];
[Self.view ADDSUBVIEW:BACKBTN];
}
-(void) Backbtnclick: (uibutton*) backbtn{
[[Nsnotificationcenter defaultcenter]postnotificationname:@ "Nextbtnaa" object:@ "inverse value"];
Hide this controller
[Self dismissviewcontrolleranimated:yes completion:nil];
}
Results:
iOS using notification inverse value