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