如何修复Mac应用程序中的CGContext错误日志?

时间:2019-04-05 07:36:57

标签: objective-c macos cocoa nsview nswindow

我有一个NSWindow控制器,其中有一个NSBox,它又包含Textfield和imageview。这些是出口。

IBOutlet NSBox *featuresBox;
IBOutlet NSImageView *screenImageView;
IBOutlet NSTextField *screenTextField;

我希望它们在我使用过BFPageControl的页面控件中

Window didload

    NSRect frame = self.window.frame;
    BFPageControl *control = [[BFPageControl alloc] init];
    control.delegate = self;
//screens array @[
//               @{@"image":@"screen_0", @"text":@"❖ _screen_0 text"},
 //              @{@"image":@"screen_1",@"text":@"❖ _screen_1 text "},
 //              @{@"image":@"screen_2",@"text":@"❖ _screen_2 text ."},
 //              @{@"image":@"screen_3",@"text":@"❖ _screen_3text"}    //                ];
    control.numberOfPages = screensArray.count;
    control.indicatorDiameterSize = 15.0;
    control.indicatorMargin = 5.0;
    control.currentPage = 0;
    control.useHandCursor = YES;
    [control setDrawingBlock: ^(NSRect frame, NSView *aView, BOOL isSelected, BOOL isHighlighted){

        frame = CGRectInset(frame, 2.0, 2.0);
        NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect: CGRectMake(frame.origin.x, frame.origin.y + 1.5, frame.size.width, frame.size.height)];
        [[NSColor whiteColor] set];
        [path fill];

        path = [NSBezierPath bezierPathWithOvalInRect: frame];
        NSColor *color = isSelected ? [NSColor colorWithCalibratedRed: (115.0 / 255.0) green: (115.0 / 255.0) blue: (115.0 / 255.0) alpha: 1.0] :
        [NSColor colorWithCalibratedRed: (217.0 / 255.0) green: (217.0 / 255.0) blue: (217.0 / 255.0) alpha: 1.0];

        if(isHighlighted)
            color = [NSColor colorWithCalibratedRed: (150.0 / 255.0) green: (150.0 / 255.0) blue: (150.0 / 255.0) alpha: 1.0];

        [color set];
        [path fill];

        frame = CGRectInset(frame, 0.5, 0.5);
        [[NSColor colorWithCalibratedRed: (25.0 / 255.0) green: (25.0 / 255.0) blue: (25.0 / 255.0) alpha: 0.15] set];
        [NSBezierPath setDefaultLineWidth: 1.0];
        [[NSBezierPath bezierPathWithOvalInRect: frame] stroke];
    }];
    [self.window.contentView addSubview: control];
    CGSize size = [control intrinsicContentSize];
    [control setFrame: CGRectMake((frame.size.width - size.width)/2, 58, size.width, size.height)];

使用BFPagecontrol委托方法可以更改页面并更改图像和文本字段的内容,但是问题是,当我尝试更改页面时,我会收到please set CG_CONTEXT_SHOW_BACKTRACE environmental variable之类的日志来解决此问题。

- (void)pageControl:(BFPageControl *)pageControl didSelectPageAtIndex:(NSInteger)index {
    screenImageView.image = [NSImage imageNamed:screensArray[index][@"image"]];
    screenTextField.stringValue = [NSString stringWithFormat:@"%@", screensArray[index][@"text"]];
}

错误

CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable
CGContextGetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
CGContextSetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

0 个答案:

没有答案