我试图在一个视图的文本字段中设置一个数字,该数字由一个类控制,并使该数字出现在另一个由其他类控制的视图中的标签中,我该怎么做?
user1525984
问问题
1556 次
2 回答
1
非常简单的方法是 NSUserDefault。我不推荐这样做,但这是获取数据的一种方式
保存
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"];
于 2012-07-16T16:25:25.077 回答
0
于 2012-07-16T16:17:48.297 回答