Ronaldo_Carry
Ronaldo_Carry
2015-12-31 09:47

iOS归档自定义对面时,其中image属性怎么反序列化的时候为nil,下面是代码

5
  • ios

//编码

  • (void)encodeWithCoder:(NSCoder *)aCoder{

    [aCoder encodeObject:_name forKey:@"name"];

    [aCoder encodeInteger:_age forKey:@"age"];

    [aCoder encodeObject:_phoneNo forKey:@"phoneNo"];

    [aCoder encodeObject:_image forKey:@"image"];

    NSLog(@"111%@",_image);

}

//解码

  • (instancetype)initWithCoder:(NSCoder *)aDecoder{

    _name = [aDecoder decodeObjectForKey:@"name"];

    _age = [aDecoder decodeIntegerForKey:@"age"];

    _phoneNo = [aDecoder decodeObjectForKey:@"phoneNo"];

    _image = [aDecoder decodeObjectForKey:@"image"];

    NSLog(@"222%@",[aDecoder decodeObjectForKey:@"image"]);

    return self;

}
其他三个属性都是有值的

Person对象定义属性的时候,UIImage直接敲好像出不来 ,手动加入了UIKit.h
#import
#import
@interface Person : NSObject
@property (strong, nonatomic) NSString *name;
@property (assign, nonatomic) NSInteger age;
@property (strong, nonatomic) NSString *phoneNo;
@property (strong, nonatomic) UIImage *image;
@end

不知道是不是这个原因导致的?求大神解答疑惑,谢谢了

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换