파일 열기 대화 상자
-
08-07-2019 - |
문제
대상 C를 배우고 간단한 지퍼 애플리케이션을 개발하려고 노력하고 있지만 대화 상자에 버튼을 삽입해야 할 때 중지 했는데이 버튼은 압축 할 파일을 선택하는 열린 파일 대화 상자를 열었습니다. 열린 파일 대화 상자를 사용한 적이없고, 그것을 열고 사용자가 선택한 파일을 char*
? 감사.
나는 gnustep (Linux)을 사용하고 있음을 기억하십시오.
해결책
다른 사람 이이 답변이 필요한 경우 여기에 다음과 같습니다.
int i;
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];
// Can't select a directory
[openDlg setCanChooseDirectories:NO];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
// Loop through all the files and process them.
for( i = 0; i < [files count]; i++ )
{
NSString* fileName = [files objectAtIndex:i];
}
다른 팁
감사합니다.
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Multiple files not allowed
[openDlg setAllowsMultipleSelection:NO];
// Can't select a directory
[openDlg setCanChooseDirectories:NO];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModal] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* urls = [openDlg URLs];
// Loop through all the files and process them.
for(int i = 0; i < [urls count]; i++ )
{
NSString* url = [urls objectAtIndex:i];
NSLog(@"Url: %@", url);
}
}
OS X V10.10+를 사용하는 사람들의 경우 Far Jangtrakool에서 교체합니다. 답변 :
if ( [openDlg runModal] == NSOKButton )
~에 의해
if ( [openDlg runModal] == NSModalResponseOK )
제휴하지 않습니다 StackOverflow