1

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??

2 Answers2

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"];
Imirak
  • 1,323
  • 11
  • 21
AAV
  • 3,785
  • 8
  • 32
  • 59
  • 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