Objective-C—— undefined symbol

标签 objective-c cocoa-touch

我正在尝试在 cocoa touch 中使用渐变。我为此使用以下代码:

#import <QuartzCore/QuartzCore.h>

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = mainView.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
[mainView.layer insertSublayer:gradient atIndex:0];

但是当我尝试编译时出现以下错误:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_CAGradientLayer", referenced from: objc-class-ref in OfficeViewController.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status

我试过清理但无济于事。不确定我还能做什么?

最佳答案

确保您确实在项目中包含了 QuartzCore 框架。它应该在 Link Binary With Libraries 阶段:

enter image description here

关于Objective-C—— undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7464399/

相关文章:

iphone - 通过 HTML 代码在 UIView 中使用透明背景色

ios - 在 iOS Objective C 中添加 Cloudinary Pod

objective-c - 如何在 Cocoa 中解析 XML?

objective-c - Objective-C以非阻塞方式实现超时

objective-c - 如何在用户的语言环境中获取星期几的名称?

iphone - 检查触摸区域而不仅仅是矩形的更好方法

ios - appStoreReceiptURL 错误

iphone - 通过通知执行选择器OnMainThread

cocoa-touch - 在没有 UITabBar 或 UINavigationBar 的 iOS 中编排多个 View 的最佳方式?

Android LayoutInflation 的 iOS/Swift 等价物