For Example :
I have two ViewController, A and B , A have
@Property(copy,nonatomic)NSString *test;
if A push to B How can update test of A, I have see some answer about Double ** and point.but I don‘t know 。Thank you!
Asked
Active
Viewed 30 times
-2

Gourav Joshi
- 2,419
- 2
- 27
- 45

niuhonghua
- 1
- 1
-
using `DelegatePattern` is one possibility have a look here: http://stackoverflow.com/a/6169104/1390857 – Thomas G. Dec 07 '16 at 07:39
-
What have u tried ??? Heard of Protocols, Unwind segues ??? – Sandeep Bhandari Dec 07 '16 at 07:39
-
why can't you use protocol or block? – Bryan Chen Dec 07 '16 at 09:33
1 Answers
1
You can use singleton class for that. Use AppDelegate for that.
Make a NSString property in AppDelegate and update the value of this NSString from AppDelegate when you will move from A to B.
In viewWillAppear() of A assign the value of NSString from AppDelegate to that in A(test)
In AppDelegate.h
@property (strong, nonatomic) NSString *value;
In ViewController A
#import "AppDelegate.h"
-(void)viewWillAppear:(BOOL)animated
{
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
self.test = appDelegate.value;
}
When push to ViewController B:
You can assign new value to AppDelegate NSString as:
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.value = @"YOUR NEW VALUE";

SNarula
- 548
- 3
- 16