これはクラス 1です。文字列と変数を保存します。このクラスではすべてが問題ないと確信しています。
-(void)SaveTextBox:(NSString*)string :(NSString*)stringsave
{
NSString *savestring = string;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:savestring forKey:stringsave];
[defaults synchronize];
}
- (IBAction)btnSaveTeamNames:(id)sender
{
[self SaveTextBox:tbTeam1.text :@"save1"];
[self SaveTextBox:tbTeam2.text :@"save2"];
[self SaveTextBox:tbTeam3.text :@"save3"];
[self SaveTextBox:tbTeam4.text :@"save4"];
[self SaveTextBox:tbTeam5.text :@"save5"];
[self SaveTextBox:tbTeam6.text :@"save6"];
[self SaveTextBox:tbTeam7.text :@"save7"];
[self SaveTextBox:tbTeam8.text :@"save8"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[NSNumber numberWithInt:TeamAmount] forKey:@"teamAmount"];
}
クラス2
これは、私が NSUserDefaults をロードしようとする場所です (おそらく間違いはこのクラスにあります)
何らかの理由で、スライダーが移動してもラベルが変更されません。また、ボイドで viewdidload 呼び出しを行って、標準の保存された文字列でラベルをロードしましたが、どちらもロードしません。
@synthesize lblTeamOne;
@synthesize lblTeamTwo;
@synthesize sliderTeamOneOutlet;
@synthesize sliderTeamTwoOutlet;
-(void)loadTeams:(NSString*)location:(NSString*)lblname
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadstring = [defaults objectForKey:location];
lblname = loadstring;
}
-(void)sliderdisplay:(UISlider *)sliderOutlet :(NSString *)lblName
{
if(0 < sliderOutlet.value && 1 >= sliderOutlet.value)
{
[self loadTeams:@"save1" :lblName];
}
if(1 < sliderOutlet.value && 2 >= sliderOutlet.value)
{
[self loadTeams:@"save2" :lblName];
}
if(2 < sliderOutlet.value && 3 >= sliderOutlet.value)
{
[self loadTeams:@"save3" :lblName];
}
if(3 < sliderOutlet.value && 4 >= sliderOutlet.value)
{
[self loadTeams:@"save4" :lblName];
}
if(4 < sliderOutlet.value && 5 >= sliderOutlet.value)
{
[self loadTeams:@"save5" :lblName];
}
if(5 < sliderOutlet.value && 6 >= sliderOutlet.value)
{
[self loadTeams:@"save6" :lblName];
}
if(6 < sliderOutlet.value && 7 >= sliderOutlet.value)
{
[self loadTeams:@"save7" :lblName];
}
if(7 < sliderOutlet.value && 8 >= sliderOutlet.value)
{
[self loadTeams:@"save8" :lblName];
}
}
-(void)loadMaximum
{
int teamAmount = [[[NSUserDefaults standardUserDefaults] objectForKey:@"teamAmount"] intValue];
NSNumber *yourNumber = [NSNumber numberWithInt:teamAmount];
float sliderMaximumDigital = [yourNumber floatValue];
[sliderTeamOneOutlet setMaximumValue:sliderMaximumDigital];
[sliderTeamTwoOutlet setMaximumValue:sliderMaximumDigital];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadTeams:@"save1" :lblTeamOne.text];
[self loadTeams:@"save1" :lblTeamTwo.text];
[self loadMaximum];
}