IOS delegate to implement values between pages

Source: Internet
Author: User

Recently, just contact with iOS development, there is no good book to read, all the functions can only be achieved by their own groping. These two days in a number of pages between the jump and the transfer of value issues,

Page jump See me another article http://blog.csdn.net/xiaotanyu13/article/details/7711954

will now use delegate to pass the value

First look at the resources on the Internet some can not understand, always feel very advanced appearance

Later on, the essence of delegate is actually:

For example, right AB two pages, a want to pass a value to B, just first in a to get a pointer B, and then assign the value you want to pass to B, then jump,

Don't talk more about the code

First we need to build a delegate:

@protocol passvaluedelegate

-(void) SetValue: (NSString *) value;

@end

In fact, this is primarily to better manage what values you need to pass and then define them in A.h.
@interface a:tttableviewcontroller{
Id<passvaluedelegate> passdelegate;

}

@property (nonatomic, retain) id<passvaluedelegate> passdelegate;

Inside the a.m.
@synthesize passdelegate;
(My class is not intuitive enough to pick someone else's text) and then when the need to jump, buttonclicked: (ID) sender{
b *_b = [[B alloc] init];
Self.passdelegate = _b;//interact with B here, the next line of code is the corresponding assignment
[Self.passdelegate Setvalue:need_pass_value]; Inside the B.h.
@interface B:nsobject <PassValueDelegate> {

nsstring* _value;
}

-(void) SetValue: (NSString *) value;

Inside the B.M.

-(void) SetValue: (NSString *) value{
_value = value;
}

When these functions are implemented

You get a value from a in B, which is the _value variable.

IOS delegate to implement values between pages

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.