【问题标题】:Customised UIView compliation error message自定义 UIView 编译错误信息
【发布时间】:2010-08-26 14:48:03
【问题描述】:

这是一个代码片段

#import "MyCustomView.h"


@implementation MyCustomView

-(void) drawRect:(CGRect)rect {
    NSLog(@"Help");
    CGContextRef myContext = [[NSGraphicsContext // 1

                               currentContext]graphicsPort];

....

然后在1,我遇到了这个错误信息:

NSGraphicsContext undeclared (first use in this function)

你知道是什么原因造成的吗?我应该包含任何头文件吗?

【问题讨论】:

  • NSGraphicsContext 听起来像是一个 Mac 类,而不是来自 Cocoa Touch(虽然我没有做过很多图形编程,所以我不确定)。

标签: objective-c ios


【解决方案1】:

在 iOS 上,您必须使用 UIGraphicsGetCurrentContext() 来获取当前的 CGContext。您的通话在 Mac OS 上有效。

【讨论】:

    【解决方案2】:

    #import <UIKit/UIKit.h>(通常在 .h 文件中完成)应该这样做,只要您没有从项目中删除 UIKit 框架。

    【讨论】:

      猜你喜欢
      • 2021-02-10
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多