패널이 비 차단이므로 패널이 열리면 코드 실행이 계속됩니다. 열린 패널은 당신이 어딘가에 대한 참조를 가지고 있지 않기 때문에 할당이 해제됩니다. -openPanel
은 편리한 생성자이며, 자동 실행 해제 된 객체를 반환합니다.이 객체는 현재 자동 실행 풀이 팝되거나 (GC 응용 프로그램에서) 수집기가 다음에 실행될 때 사라집니다. 귀하의 경우, 귀하의 방법이 완료 되 자마자입니다. 당신이 패널이 곁에하려면
, 당신은 특별히 didEndSelector에 -release
에게 연속적으로 다음을 -retain
를 사용하여 보유하고 있어야합니다 : 당신이 쓰레기 수거를 사용하는 경우, 유지 및 해제
- (void)showPanel
{
NSOpenPanel *openPanel = [[NSOpenPanel openPanel] retain]; //note the retain
[openPanel beginForDirectory:nil
file:nil
types:[NSImage imageFileTypes]
modelessDelegate:self
didEndSelector:@selector(myOpenPanelDidEnd:returnCode:contextInfo:)
contextInfo:NULL];
}
- (void)myOpenPanelDidEnd:(NSOpenPanel *)panel returnCode:(int)returnCode contextInfo:(void*)contextInfo
{
NSArray* fileNames = [panel filenames];
[panel release];
//do something with fileNames
}
은 더 없다 -ops이므로 NSOpenPanel
에 대한 강력한 참조 (예 : 인스턴스 변수에 저장)를 저장해야합니다.