I have a NSPopUpButton but at first time launch this does not set correctly the first value. I have set awakeFromNib but the NSPopUpMenu is empty. Only the second time and the next it works correctly. Thanks in advance.
-(IBAction)chancepesoalert:(id)sender{
int selection = [(NSPopUpButton *)sender indexOfSelectedItem];
NSNumber *valore = [NSNumber numberWithUnsignedLongLong:(30*1000*1000)];
if (selection == 0) {
valore = [NSNumber numberWithUnsignedLongLong:(30*1000*1000)];
NSLog(@"Selezionato 0");
}
if (selection == 1){
valore = [NSNumber numberWithUnsignedLongLong:(50*1000*1000)];
NSLog(@"Selezionato 1");
}
if (selection == 2){
valore = [NSNumber numberWithUnsignedLongLong:(75*1000*1000)];
NSLog(@"Selezionato 2");
}
if (selection == 3){
valore = [NSNumber numberWithUnsignedLongLong:(100*1000*1000)];
NSLog(@"Selezionato 3");
}
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:valore forKey:@"SetPesoAlert"];
[userDefaults synchronize];
}
-(void)awakeFromNib {
unsigned long long value = [[[NSUserDefaults standardUserDefaults] objectForKey:@"SetPesoAlert"] unsignedLongValue];
int index;
if (value == (30*1000*1000)) {
index =0;
}
if(value == (50*1000*1000)) {
index =1;
}
if(value == (75*1000*1000)) {
index =2;
}
if(value == (100*1000*1000)) {
index =3;
}
[pesoalert selectItemAtIndex:index];
}