IOS uses delegate to transmit values between pages

Source: Internet
Author: User

Bin Zi encountered a problem when he was just in touch with the IOS project today. During page skipping, he needed to pass parameters. I have found many ways to access the Internet, and I have not found any good methods in the book. All functions have to be explored by yourself. Finally, I found a post from a netizen. Now I use delegate to implement it. In fact, the essence of Delegate's passing value is: for example, if a wants to pass the value to B on the right AB page, you just need to get the pointer of B in a first, then assign the value to B, and then jump,

Let's talk about the Code directly.

First, we need to create a delegate:

@protocol PassValueDelegate- (void)setValue:(NSString *)value;@end

Then define in A. H.

 
@interface A:TTTableViewController{id<PassValueDelegate> passDelegate;}@property(nonatomic, retain) id<PassValueDelegate> passDelegate;

In A.M

@ Synthesize passdelegate; my class is not intuitive enough to extract others' texts.) When redirecting:
Buttonclicked :( ID) sender {B * _ B = [[B alloc] init]; self. passdelegate = _ B; // interaction with B. The next code is the corresponding value [self. passdelegate setvalue: need_pass_value];

In B .h

@interface B : NSObject <PassValueDelegate> {        NSString* _value;}- (void) setValue:(NSString *) value;

In B. M

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

After these functions are implemented

You get the value from a in B, that is, the variable _ value.

The source of some of the Code: http://blog.csdn.net/xiaotanyu13/article/details/7714007


Related Article

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.