IOS Multi View-View toggle code block parameter switch

Source: Internet
Author: User

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

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.