我有一個NSPopUpButton,但在第一次啓動時沒有正確設置第一個值。我設置了awakeFromNib,但NSPopUpMenu是空的。只有第二次和下一次它正常工作。 在此先感謝。設置NSPopUpButton在第一次啓動
-(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];
}
我不明白你在問什麼。當你第一次啓動應用程序時,你想在彈出窗口中看到什麼?你如何將菜單項放在彈出式菜單中? – rdelmar 2012-03-31 16:45:49
我想默認索引= 0應用程序的第一次啓動,第二次和下一個用戶選擇什麼。 現在它選擇索引= 0,但不能正常工作。 – Joannes 2012-04-01 15:09:35