0

我正在编写一个应用程序,其中涉及我覆盖 UIViews 中的 drawRect 函数以将不同的形状绘制到应用程序中。

我通常使用内置的 SenTestingKit 对我的所有应用程序进行单元测试。一旦我包含任何 contextRefCG 绘图内容,每当我尝试运行测试时,我都会看到一系列异常并且测试不会运行。如果我注释掉 drawRect 函数,测试将再次编译并运行。

我看到的错误消息是:

Undefined symbols for architecture i386:
  "_CGContextAddArc", referenced from:
      -[HeartShapeView drawRect:] in HeartShapeView.o
  "_CGContextAddLineToPoint", referenced from:
      -[SquareShapeView drawRect:] in SquareShapeView.o
      -[HeartShapeView drawRect:] in HeartShapeView.o
  "_CGContextBeginPath", referenced from:
      -[SquareShapeView drawRect:] in SquareShapeView.o
      -[HeartShapeView drawRect:] in HeartShapeView.o
  "_CGContextClosePath", referenced from:
      -[SquareShapeView drawRect:] in SquareShapeView.o
      -[HeartShapeView drawRect:] in HeartShapeView.o

这是我的 DrawRect 的 SquareShapeView 之一中的代码

- (void)drawRect:(CGRect)rect
{
    CGFloat small = rect.size.width;
    small = (rect.size.height <= rect.size.width) ? rect.size.height : small;

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);

    CGContextBeginPath(context);

    CGContextMoveToPoint(context, 0.0f, 0.0f);
    CGContextAddLineToPoint(context, 0.0f, small);
    CGContextAddLineToPoint(context, small, small);
    CGContextAddLineToPoint(context, small, 0.0f);

    CGContextClosePath(context);
    CGContextSetLineWidth(context, 1.0f);

    CGContextStrokePath(context);
}
4

1 回答 1

1

您忘记将CoreGraphics框架包含到您的测试目标中

于 2013-06-17T08:57:13.363 回答