我正在尝试保存一个包含 CGRect
值的数组。我知道 plists 与 CGRect
类型不兼容,所以我稍微修改了我的代码,现在我存储 NSNumber
而不是存储 rect 值——我拆分了 rect 值分为四个值:x、y、宽度、高度。
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetMinX(rawRect)]];
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetMinY(rawRect)]];
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetWidth(rawRect)]];
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetHeight(rawRect)]];
现在 myArray1
仅包含 NSNumber
,我试图将这些值存储到 plist 中,但我无法将这些值加载回来。如果我的代码有任何错误,任何人都可以纠正我吗?
提前致谢;我在等你的宝贵信息。
最佳答案
CGRect rect = CGRectMake(0, 0, 320.0f, 480.0f);
//you need to translate the rect into a compatible "Plist" object such as NSString
//luckily, there is a method for that
[rectArray addObject:NSStringFromRect(rect)];
//save into a plist
...
在检索这个值时
CGRect rect = CGRectFromString([rectArray objectAtIndex:0]);
关于objective-c - 将 CGRect 存储到 plist 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5886981/