gpt4 book ai didi

cocoa - 尝试访问超出数组范围的索引

转载 作者:行者123 更新时间:2023-12-03 16:47:54 25 4
gpt4 key购买 nike

// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];

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

// Enable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:YES];

// 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];
NSString *string1;
// Loop through all the files and process them.
for( i = 0; i < [files count]; i++)
{
NSString* fileName = [files objectAtIndex:i];
// Do something with the filename.
string1 = [[NSString alloc] initWithContentsOfFile:fileName];
if(string1 == nil)
{
NSLog(@"Error reading file");
}
else
{

}
}
}

当我第一次单击“打开”按钮时,它将打开“打开”对话框并且工作正常但是当我第二次单击“打开”按钮时,它给出了类似的错误

* -[NSCFArray objectAtIndex:]:索引 (0) 超出界限 (0)

最佳答案

不确定这是否能解决您的问题,但 runModalForDirectory 已弃用,请考虑使用 runModal相反。

关于cocoa - 尝试访问超出数组范围的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7369776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com