Saturday, 10 August 2013

New ways to transfer data between view controllers

New ways to transfer data between view controllers

I have a problem with transferring data between UIViewController and I
don't find answers in former questions.
Situation : I have a first viewController ('CalViewController') which
allows users to input data. Then I calculate with those datas a number
(named 'calories' for example). The next views are two UIViewController
(DrinksViewController & FoodViewController)displayed in a
TabBarControllerand I need value of 'calories'.
What I've tried : -prepareForSegue method : It doesn't work because segues
(symbol in storyboard is a link between two points) in a
TabBarControllerare not as others (symbol in storyboard is arrow through a
door).
-'didSelectViewController' method : This method is not "activated" to
display the first view of a TabBarController. So I succeed to transfer
Calories to my second ViewController in the TabBarController (ie
FoodViewController) but not to my first viewController in the
TabBarController (ie DrinksViewController).
-call the "original" value : Here what I've done in CalViewController
(after imported DrinksViewController.h)
DrinksViewController *dvc = [[DrinksViewController alloc] init];
dvc.caloriesImported = 456;
I don't know why this third way is not working.
Problem : My value of Caloriesis not transferred from CalViewController to
DrinksViewControlller. Any ideas ?

No comments:

Post a Comment