0

Possible Duplicate:
Passing Data between View Controllers

I got an array/dictionary needs to transfer from viewController1 to viewController3. Save it into plist or NSUserDefault is too complicate, and I want to find a more effective way to deal with it. Do guys have any suggestion for it? Thanks for your prompt helped in advance.

Resolution: Finally I found out a way to fix the transfer, which is most effective way I think. Firstly, we create a singleton class and make a method for saving the array/dictionary. Then, declare an array object in *.h file. Next step, call this singleton method to save your array. Last step, call the method and you'll get your data~

It seems working pretty well. We don't need to transfer data view to view anymore, cooll~

Community
  • 1
  • 1
Lothario
  • 300
  • 1
  • 5
  • 10

2 Answers2

1
@interface ViewController3 : UIViewController

//Add a public property for your ViewController3
@property (strong, nonatomic) NSArray *nameArray;

@end


// transfer it like this
NSArray *nameArray = @[@"Green", @"Gordan"];
ViewController3 *viewController3 = [[ViewController3 alloc] init];
viewController3.nameArray = nameArray;
sunkehappy
  • 8,970
  • 5
  • 44
  • 65
  • wow, thanks. It looks worked well. – Lothario Nov 29 '12 at 03:22
  • By using this solution we need to assign viewController3 to viewController2 at first. Like below: ViewController2 *viewController2 = [[ViewController2 alloc] init]; viewController2.viewController = viewController3; [self.navigationController pushViewController:viewController animated:YES]; – Lothario Nov 29 '12 at 03:57
  • But in your question description you just mention the array/dictionary you want to transfer from `viewController1` to `viewController3`. If you need to transfer view controller. It's also OK. – sunkehappy Nov 29 '12 at 04:17
  • there've viewController2 between 1 and 3. Views pushing 1 -> 2 ->3, so that we need to transfer array from 1 to 2 and 2 deliver to 3 in regularly, which is too much work needs to do. – Lothario Nov 29 '12 at 06:25
  • Is your viewController1 the root view controller? If it is, you can get the array like this:`appDelegate.window.rootViewController.nameArray` – sunkehappy Nov 29 '12 at 06:40
0

This is easy. Declare a NSDictionary pointer variable in viewController3 and then assign it.

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264