歸檔解檔,數據錯誤

tags:    時間:2013-12-03 18:40:58
為什麼我這樣做解檔出來的路寬是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);
 
------解決方案--------------------
周日還在忙啊
------解決方案--------------------
引用 1 樓 yang8456211 的回復:
周日還在忙啊

研究生么有周六周日~~~~
------解決方案--------------------
高深,我是菜鳥我不懂。
------解決方案--------------------
引用 3 樓 jingtingmeihao 的回復:
Quote: 引用 1 樓 yang8456211 的回復:

周日還在忙啊

研究生么有周六周日~~~~

額。看來比我大。。。
------解決方案--------------------
[encoder encodeObject:[NSNumber numberWithBool:self.roadWidth] forKey:@"roadWidth"];

你在歸檔的時候把這個路寬屬性歸檔成布爾類型了,所以自然就只能是0或者1了。

推薦閱讀文章

Bookmark the permalink ,來源:互聯網