私のウィンドウ、ビュー、およびサブビューをプログラムで作成するコードは次のとおりです。問題は私のサブビュー "filterView2"が追加されたときに[filterView addSubview:filterView2];
がその行でクラッシュします。私が含むことを忘れたか、間違っていたことはありますか?ありがとう!プログラムによるビューとサブビューの作成
NSRect mainFrame = [[NSScreen mainScreen] frame];
NSRect helpFrame = NSZeroRect;
float width = 600;
float height = 400;
helpFrame.origin.x = (mainFrame.size.width - width)/2.0;
helpFrame.origin.y = 260.0;
helpFrame.size.width = width;
helpFrame.size.height = height;
helpWindow2 = [[BrightnessView windowWithFrame:helpFrame] retain];
// Configure window.
[helpWindow2 setReleasedWhenClosed:YES];
[helpWindow2 setHidesOnDeactivate:NO];
[helpWindow2 setCanHide:NO];
[helpWindow2 setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
[helpWindow2 setIgnoresMouseEvents:YES];
[helpWindow2 setBackgroundColor:[NSColor clearColor]];
[helpWindow2 setOpaque:NO];
// Configure contentView.
NSView *filterView = [helpWindow2 contentView];
[filterView setWantsLayer:YES];
//add subview
NSView *filterView2 = [helpWindow2 contentView];
[filterView addSubview:filterView2];
//CALayer for filterView
CALayer *theLayer = [CALayer layer];
theLayer.opacity = 0;
[filterView setLayer:theLayer];
CGColorRef bgColor = CGColorCreateGenericRGB(0, 200, 255, 1);
theLayer.backgroundColor = bgColor;
CGColorRelease(bgColor);
theLayer.borderColor = CGColorGetConstantColor(kCGColorWhite);
theLayer.cornerRadius = 8.0;
float helpOpacity = (([NSApp isActive] ? 1 : 0));
[[[helpWindow2 contentView] layer] setOpacity:helpOpacity];
[window addChildWindow:helpWindow2 ordered:NSWindowAbove];
helpWindow2関数 "contentView"は、新しいバージョンのビューを割り当てるか、少なくとも保持しますか?どのようなクラッシュがここで起こっているのですか? EXC_BAD_aLLOC?クラッシュと "contentView"関数/プロパティ/変数の見た目についての詳細を提供してください。それが何であるかを知る必要がある – chikuba
EXC_BAD_ACCESSはエラーメッセージであり、変数はちょうど(id)contentView –
です。通常、あなたはあなたが解放されたために保持されていないものにアクセスしようとしていますメモリ(例えば)。この場合、実際にはデザインを見なければなりません。それは自分のサブビューのビューですか?本当に私には聞こえませんので、あなたがあなたのオブジェクトに入れたcontentViewの新しいインスタンスを作成しようとすると、何かを失わないようにコピーを作成することさえできます。 – chikuba