I was trying to set a number in a textfield in one view, that is controlled by one class and make this number appear in a label that is in another view controlled by other class, how do i do it??
Asked
Active
Viewed 1,556 times
1
-
Are you using MVC design? Do you have a model that is separated from the view/controller? – mkral Jul 16 '12 at 16:12
-
Read a recent question http://stackoverflow.com/a/11508245/468724 – Inder Kumar Rathore Jul 16 '12 at 16:16
-
[Another question](http://stackoverflow.com/a/8383785/468724). There are many question related to this.Try to search.Though they are not exactly what you want but they are similar to your problem. – Inder Kumar Rathore Jul 16 '12 at 16:20
2 Answers
1
Very simple way is NSUserDefault. I don't recommend this but this a way to get data
Saving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];
// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];
// saving a Double
[prefs setDouble:3.1415 forKey:@"doubleKey"];
// saving a Float
[prefs setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize];
Retrieving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];
// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];
// getting an Float
float myFloat = [prefs floatForKey:@"floatKey"];
-
I was nearly done typing the exact same answer. I prefaced it with "not necessarily the best, but it works" – mistahenry Jul 16 '12 at 16:27
-
@sunrize920, LOL. That is why i wrote I don't recommend this. But its a way to solve the problem Gabriel Molter having. – AAV Jul 16 '12 at 16:30
0
multiple repost like :
How can I pass a parameter into a view in iOS?
iphone Pass String to another .m file in project
you can also looks segue
and protocol delegate

Community
- 1
- 1

Damien Locque
- 1,810
- 2
- 20
- 42