NSComboBoxが入っているNSAlertシートがあります。ユーザーがNSAlertのボタンを押したときに、コンボボックスの値を渡すにはどうすればよいですか?
コード:
NSComboBox* comboBox = [[NSComboBox alloc] initWithFrame:NSMakeRect(0, 0, 150, 26)];
[comboBox setTitleWithMnemonic:@"2"];
for (int i=2; i<[array count]+1; i++){
[comboBox addItemWithObjectValue:[NSString stringWithFormat:@"%i", i]];
}
[comboBox setEditable:NO];
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Okay"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Choose a number"];
[alert setAccessoryView:comboBox];
[alert beginSheetModalForWindow:_window modalDelegate:self didEndSelector:@selector(alertToChooseX:returnCode:contextInfo:) contextInfo:nil];
- (void)alertToChooseX:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
if (returnCode == NSAlertFirstButtonReturn) {
NSLog(@"Pressed Okay");
}
}