objective-c - objective-c : How to use UIImage as a property in my model?

标签 objective-c

我有一个Player模型:

Player.h:

#import <Foundation/Foundation.h>
@interface Player : NSObject

@property (nonatomic, strong) UIImage *image;
@property (nonatomic, strong) NSMutableArray *answers;

@end

玩家.m:

#import <Foundation/Foundation.h>
#import "Player.h"

@interface Player ()

@end

@implementation Player

- (id)init {
    if (self = [super init]) {
        self.answers = [[NSMutableArray alloc] init];
        self.image = [UIImage imageNamed:@"defaultProfileImage"]; // <-------------- error
    }
    return self;
}

@end

但是这会显示错误:使用未声明的标识符“UIImage”

如何在我的模型中使用 UIImage?

最佳答案

您需要导入

#import <UIKit/UIKit.h>

这样UIImage就被识别了

关于objective-c - objective-c : How to use UIImage as a property in my model?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32158299/

相关文章:

ios - objective-c - 注销功能

iphone - 如何一起使用 xib 和 UIView 子类?

objective-c - 将 NSPredicateEditor 绑定(bind)到共享用户默认 Controller

iphone - iOS 应用程序事件处理程序的正确位置(MVC 方面)是什么?

ios - obj-c AFNetworking 2.0 POST 请求不起作用

ios - 除了 Segues,如果我使用 Storyboard,如何在 iOS 中从一个 View 转到另一个 View ?

ios - 具有 n 个按钮的水平 ScrollView : [iOS]

ios - UIImagePickerController 允许我拍摄照片和视频,但不允许我保存它们或 "use"它们

ios - AVAudioPlayer 没有从临时文件路径播放声音

ios - 64 位随机种子