In iOS design, there are many ways that a view can pass parameters to the next view page at the same time as the switch, where the method of FirstViewController.h is implemented by code blocks.
#import <UIKit/UIKit.h>
Declaring code blocks
typedef void (^postvalueblock) (NSString *info);
@interface firstviewcontroller:uiviewcontroller<uitextfielddelegate>
@property (strong,nonatomic) Uitextfield *textname;
@property (strong,nonatomic) NSString *stringb;
@property (strong,nonatomic) postvalueblock Block; @end firstviewcontroller.m
#import "FirstViewController.h"
@interface Firstviewcontroller ()
@end
@implementation Firstviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Set the main screen background color
Self.view.backgroundcolor=[uicolor Greencolor];
Create a text box
Self.textname=[[uitextfield alloc]initwithframe:cgrectmake (100, 100, 150, 40)];
self.textname.borderstyle=1;
Specify Proxy
self.textname.delegate=self;
Pass Value
SELF.TEXTNAME.TEXT=SELF.STRINGB;
[Self.view AddSubview:self.textName];
}
Implementing code block methods
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
Calling code block methods
if (self. Block) {
Self. Block (Textfield.text);
}
Toggle Page
[Self Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "Toggle Success");
}];
Hide keyboard
if ([TextField Isfirstresponder]) {
[TextField Resignfirstresponder];
}
return YES;
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning]; } @end ViewController.h
#import <UIKit/UIKit.h>
#import "FirstViewController.h"
@interface viewcontroller:uiviewcontroller<uitextfielddelegate>
@property (strong,nonatomic) NSString *stringa;
@property (strong,nonatomic) UIButton *mybutton;
@property (strong,nonatomic) Uitextfield *textname; @endViewController. m
#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Background color
Self.view.backgroundcolor=[uicolor Bluecolor];
Create a text box
Self.textname=[[uitextfield alloc]initwithframe:cgrectmake (100, 100, 150, 50)];
self.textname.borderstyle=1;
Specify Proxy
self.textname.delegate=self;
Pass the reference
Self.textname.text=self.stringa;//code block
[Self.view AddSubview:self.textName];
Create button
Self.mybutton=[[uibutton Alloc]initwithframe:cgrectmake (150, 160, 50, 50)];
Self.mybutton.backgroundcolor=[uicolor Redcolor];
[Self.mybutton settitle:@ "Next" forstate:uicontrolstatenormal];
[Self.mybutton addtarget:self Action: @selector (NextPage) forcontrolevents:uicontroleventtouchupinside];
[Self.view AddSubview:self.myButton]; }
-(void) nextPage
{
Firstviewcontroller *firstvc=[[firstviewcontroller Alloc]init];
Pass value to next page
Firstvc.stringb=self.textname.text;
Implementing code blocks (passing values to this page)
firstvc.block=^ (NSString *info) {
Self.textname.text=info;
};
[Self PRESENTVIEWCONTROLLER:FIRSTVC animated:yes completion:^{
NSLog (@ "Toggle Success");
}];
}
Agreement
Proxy method
-(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
{
if ([TextField Isfirstresponder]) {
[TextField Resignfirstresponder];
}
return YES;
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning]; }
@end
1. From the first view (the only) to the next view (forward parameter) 1, from the view parameter (the only one of) to the previous view (reverse parameter)
IOS Multi View-View toggle code block parameter switch