Objective C writetoFile не работает, когда получить путь к файлу из textfied (файловый браузер) - PullRequest
0 голосов
/ 04 июля 2018

Я пытаюсь сохранить файл по пути, который я ввожу вручную в текстовое поле или выбираю из FileBrowser. Однако это не работает.

Если я перетаскиваю путь к текстовому полю, он работает нормально Не могли бы вы помочь мне.

- (IBAction)btnRawDataPath:(id)sender {
    _txtLog.stringValue = @"";
    // Create the File Open Dialog class.
    NSOpenPanel* openDlg = [NSOpenPanel openPanel];

    // Enable the selection of files in the dialog.
    [openDlg setCanChooseFiles:NO];

    // Multiple files not allowed
    [openDlg setAllowsMultipleSelection:NO];

    // Can't select a directory
    [openDlg setCanChooseDirectories:YES];

    // Display the dialog. If the OK button was pressed,
    // process the files.
    if ( [openDlg runModal] == NSModalResponseOK )
    {
        // Get an array containing the full filenames of all
        // files and directories selected.
        NSArray* urls = [openDlg filenames];

        // Loop through all the files and process them.
        for(int i = 0; i < [urls count]; i++ )
        {
            //fileList.push_back(std::string([[[urls objectAtIndex:i] path] UTF8String]));
            NSString* url = [urls objectAtIndex:i] ;
            NSLog(@"Url: %@", url);
           _txtRawDataPath.stringValue = url;
        }
    }
}

// EXCUTE

NSString *filePath = [_txtRawDataPath.stringValue stringByAppendingPathComponent:@"outputFIle.csv"];



NSData* settingsData;
settingsData = [mainString dataUsingEncoding: NSASCIIStringEncoding];

if ([settingsData writeToFile:filePath atomically:YES ])
    NSLog(@"%@", filePath);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...