控制台的报错百度无果,应该是控件的上下文错误

控制台的报错百度无果,应该是控件的上下文错误

Jul  1 10:47:47  zuoye[735] <Error>: CGContextSetLineWidth: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Jul  1 10:47:47  zuoye[735] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Jul  1 10:47:47  zuoye[735] <Error>: CGContextMoveToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Jul  1 10:47:47  zuoye[735] <Error>: CGContextAddLineToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Jul  1 10:47:47  zuoye[735] <Error>: CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.



代码如下:

//

//  ChartViewController.m

//  zuoye

//

//  Created by 刘悦 on 2017/6/29.

//  Copyright © 2017年 BNR. All rights reserved.

//


#import "ChartViewController.h"

#import "Quartz2d.h"

@interface ChartViewController ()


@end


@implementation ChartViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];

    UIButton *buttonReturn = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height-60, 100, 50)];

    buttonReturn.backgroundColor = [UIColor redColor];

    [buttonReturn setTitle:@"返回" forState:UIControlStateNormal];

    [buttonReturn addTarget:self action:@selector(jumpFirst) forControlEvents:UIControlEventTouchDown];

    [self.view addSubview:buttonReturn];

    //绘图的区域

    UIView *viewblue = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 600)];

    

    viewblue.backgroundColor = [UIColor blueColor];

    [self.view addSubview:viewblue];

    

    Quartz2d *quartzView = [[Quartz2d alloc]initWithFrame:viewblue.frame];

    [self.view addSubview:quartzView];

    [quartzView drawXY];

    [quartzView setNeedsDisplay];

    

}



- (void)jumpFirst{

    [self dismissViewControllerAnimated:YES completion:nil];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end

quartz2d的代码如下

//

//  Quartz2d.m

//  zuoye

//

//  Created by 刘悦 on 2017/6/29.

//  Copyright © 2017年 BNR. All rights reserved.

//


#import "Quartz2d.h"


@implementation Quartz2d



// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

    [self drawXY];


}


- (void)drawXY{

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 1.0);

    [[UIColor greenColor]setStroke];

    CGContextMoveToPoint(context, 50, 400);

    CGContextAddLineToPoint(context, 414, 400);

    CGContextStrokePath(context);

    

}


@end



正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
Tender10 2017-07-02 10:56:40

以后注意下就可以啦!

Tender10 2017-07-01 13:47:25

ChartViewController类中多了一行代码 [quartzView drawXY];这个在Quartz2d的drawRect方法中  [self drawXY];其实已经调用过drawXY方法了,所以只需要将ChartViewController类中的[quartzView drawXY];注释掉即可。

  • 提问者 慕慕9485116 #1
    后面发现多余就删掉了,自己又忘记了,结果就不能再现控制台的结果了。。。原来是这行代码的原因。。
    2017-07-01 14:47:30
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
iOS入门:基础语法与常用控件
  • 参与学习       1337    人
  • 提交作业       712    份
  • 解答问题       1878    个

很多人都在疑问没有基础该怎么学习iOS开发?不用担心,本路径采用游戏关卡式的教学模式,并且以经典OC与最新Swift双重结合的教学内容,帮助大家快速掌握两种iOS开发语言基础,去掉“零”标签。

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师