1
NSComboBox가있는 NSAlert 시트가 있습니다. 사용자가 NSAlert 버튼을 누르면 콤보 상자 값을 전달할 수 있습니까?
코드 :NSAlert 시트 내에있는 NSComboBox 값 전달
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");
}
}
그런 식으로 생각하고 있었지만 NSAlert에 값을 전달할 방법이 있다고 생각했습니다. 고맙습니다! 그리고 btw, 나는 ARC를 사용하지 않으므로 릴리즈가 : P –
@PedroVieira 당신은 환영합니다 :) –