私は次のコードで苦労しています。私はそれが間違っていることを望ましくない。 コードがクラッシュに関してコメントしている:私は、彼は* [NSControlのstringValue]から返さNSStringのだろうかNSMutableDictionaryの問題setObject:forKey - クラッシュ
- (IBAction) SavePreset: (id) sender
{
NSString *presetName = [nameCombo stringValue]; // nameCombo is a NSComboBox*
NSUserDefaults *vmDefaults = [NSUserDefaults standardUserDefaults];
NSMutableDictionary *projectionPresets = [vmDefaults objectForKey: kVmGeorefPresetKey];
BOOL doSave = YES;
NSString *dictEntry = [projectionPresets objectForKey: presetName];
if (dictEntry) {
// this branch is not tested yet, plan to test when the rest is working.
int userChoice;
userChoice = NSRunAlertPanel(@"Save Preset",
@"This preset (%s) already exists, modify?",
@"OK", @"Cancel", nil, presetName);
doSave = (userChoice == NSAlertDefaultReturn);
if (doSave) {
[nameCombo addItemWithObjectValue: presetName];
}
}
if (doSave)
{
// projParamText is of class NSTextField*
NSString *presetParam = [projParamText stringValue];
// Up to this point, everything works as expected
// But, the following statement crashes silently.
[projectionPresets setObject: presetParam forKey: presetName];
// and the subsequent code is never executed
[savePresetButton setEnabled: NO];
}
}
は、内部の文字列reperesentaionまたは私はテキストを編集する場合は変更されません新しいNSStringのへのポインタを返します後でNSTextFieldの
サイレントにクラッシュしますか?例外もエラーもありません。ブレークポイントでテストしましたか? – Joze
stringValueの呼び出し後にpresetParamの型のデバッガを確認できますか?また、クラッシュログ出力を表示してください –