问题
I'm have a routine based on code found on this forum:
+ (FSRef)useOpenFileToGetFSRef:(NSString **)fileName requiredFileType: (NSString*) requiredFileType
{
FSRef fileFSRef;
NSArray* fileTypes = [[NSArray alloc] initWithObjects:requiredFileType, nil];
//http://stackoverflow.com/questions/11815784/objective-c-nsopenpanel-get-filename
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
[openDlg setFloatingPanel:YES];
[openDlg setCanChooseDirectories:NO];
[openDlg setCanChooseFiles:YES];
[openDlg setAllowsMultipleSelection:YES];
[openDlg setAllowedFileTypes:fileTypes];
if ( [openDlg runModal] == NSOKButton ) //<== CRASHES ON CALL TO runModal
{
NSArray* filePaths = [openDlg URLs];
//only getting 1st file
NSURL *fileUrl = [filePaths objectAtIndex:0];
*fileName = [fileUrl path];
CFURLGetFSRef((CFURLRef)fileUrl, &fileFSRef);
}
return fileFSRef;
}
The app repeatably crases on the call to runModel:
What could explain this?
Thanks very much in advance to all for any info.
System info: OS X 10.8.4. Compiled using ARC.
回答1:
I actually think you had a breakpoint on all exceptions. I just ran into this and was looking for why. I ran into this post, but then found the following.
NSOpenPanel crashes when debugging with Xcode 4.5.1
When you recreated the project, the breakpoints got reset.
回答2:
It looks like there was some anomaly in the project file. I copied all the source files and xib files to a new project, and after that NSOpenPanel runModal worked as expected.
回答3:
Had a similar problem. I had not been storing all of the project files (same code worked perfectly on another machine). I removed them one-by-one, no effect. Removed DerivedData
directory and no effect.
lappy:vStacks ndunn$ hg st . ? StacksGui3.xcodeproj/project.xcworkspace/xcuserdata/ndunn.xcuserdatad/UserInterfaceState.xcuserstate ? StacksGui3.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcschemes/StacksGui3.xcscheme ? vStacks.xcodeproj/project.xcworkspace/xcuserdata/ndunn.xcuserdatad/UserInterfaceState.xcuserstate ? vStacks.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist ? vStacks.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcschemes/vStacks.xcscheme ? vStacks.xcodeproj/xcuserdata/ndunn.xcuserdatad/xcschemes/xcschememanagement.plist
I was about to do what you did, but I ended up:
1 - deleting my vStacks.xcodeproj and source
2 - creating another one with the same name
3 - deleted the new one
4 - recovered the entire project from source control.
Note: Not sure if steps 2 and 3 are necessary, but 1 and 4 certainly are.
来源:https://stackoverflow.com/questions/17477263/nsopenpanel-runmodal-crashes