first of all, i’m using storyboard.
i first created a viewcontroller controlled by one class, and in this view ther is a textfield where the user puts a number, a button uses modal to take the user to a tabbar controller with two itens “one” and “two”, “one” and “two” takes us to different viewcontrollers (controlled by the same class), but both with a label, this label have to present the value that user put in the textfield at the first view… i only know how to do that by:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:[mytextfield.text intValue] forKey:@"integerKey"];
in one class, and:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSInteger mynumber = [prefs integerForKey:@"integerKey"];
NSString *mystring = [[NSString alloc] initWithFormat:@"%i", mynumber];
mylabelonone.text = mystring;
mylabelontwo.text = mystring;
in the other class…
but, when i test it in the simulator, and click the button that takes us to “one” the label is empty, even so, when i click the item that goes to “two”, the label is there with the exact number!
I tried to change “one” and “two” order in the tabbar controller and then the problem happens with “two” and one is perfect!
I don’t have any idea of what can be happening…
Table View Controllers work in an interesting way. When switching between between tabs, methods such as
viewWillAppearorviewWillDisappear.So the question becomes where you are putting the lines of code posted. That code will work, but only if the first code is run before the user taps a different tab, and the second part of your code runs after the first.
– tabBarController:shouldSelectViewController:andtabBarController:didSelectViewController:Another way would be to import a view and then set a variable from the second view while still in the first.