归档解档,数据错误
为什么我这样做解档出来的路宽是1啊,而我的数据里明明是350啊~~~~跪求大神看看啊
-(void)encodeWithCoder:(NSCoder *)encoder
{
[super encodeWithCoder:encoder];
[encoder encodeObject:[NSValue valueWithCGPoint:self.startPoint] forKey:@"startPoint"];
[encoder encodeObject:[NSValue valueWithCGPoint: self.imageTranslate] forKey:@"endPoint"];
[encoder encodeObject:[NSNumber numberWithBool:self.roadWidth] forKey:@"roadWidth"];
[encoder encodeObject:[NSNumber numberWithBool:self.roadIslandWidth] forKey:@"roadIslandWidth"];
[encoder encodeObject:[NSNumber numberWithBool:self.upOrLeftLaneNum] forKey:@"upOrLeftLaneNum"];
[encoder encodeObject:[NSNumber numberWithBool:self.downOrRightLaneNum] forKey:@"downOrRightLaneNum"];
}
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super init])
{ self.startPoint=((NSValue *)[decoder decodeObjectForKey:@"startPoint"]).CGPointValue;
self.endPoint=((NSValue *)[decoder decodeObjectForKey:@"endPoint"]).CGPointValue;
self.roadWidth=((NSNumber *)[decoder decodeObjectForKey:@"roadWidth"]).integerValue;
self.roadIslandWidth=((NSNumber *)[decoder decodeObjectForKey:@"roadIslandWidth"]).integerValue;
self.upOrLeftLaneNum=((NSNumber *)[decoder decodeObjectForKey:@"upOrLeftLaneNum"]).integerValue;
self.downOrRightLaneNum=((NSNumber *)[decoder decodeObjectForKey:@"downOrRightLaneNum"]).integerValue;
}
NSMutableData *data = [NSMutableData data ];解档错误
//创建一个归档类
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
[archiver encodeObject:[subviews objectAtIndex:i] forKey:@"RoadSectionView"];
[archiver finishEncoding];
[data writeToFile:[self getFilePath] atomically:YES];
//将数据写入文件里
/* NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.view];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:(NSMutableData *)data];
[archiver encodeObject:self.view forKey:@"RoadSectionView"];
[archiver finishEncoding];*/
NSMutableData *data1 = [NSMutableData dataWithContentsOfFile:[self getFilePath]];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:data1];
RoadSectionView *p3 = [unarchiver decodeObjectForKey:@"RoadSectionView"];
NSLog(@"%d",p3.roadWidth);