在class 1
我保存int
转换为 astring
时,在class 2
我尝试加载此字符串时,由于某种原因它不起作用,当我将从文本框中取出的字符串写入loadString
文本框时class 2
,文本框保持为空。当我在class 1
文本框中做同样的事情时变成“1”。
1.m级
- (void)viewDidLoad
{
[super viewDidLoad];
countForString = 1;
saveString = [[NSString alloc]initWithFormat:@"%i", countForString];
[self SaveTextBox:saveString :@"Number"];
}
-(void)SaveTextBox:(NSString*)string :(NSString*)stringsave
{
NSString *savestring = string;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:stringsave];
[defaults synchronize];
}
2.m级
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadString:@"Number":teamString];
tbTeamPlayer.text = teamString;
}
-(void)loadString:(NSString *)location:(NSString *)saveInString
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:location];
saveInString = loadstring;
}