In my app,
I have one array filterimage in that array some images is there. I want that array data on another view.
I try to set nsuserdefault for filterimage with 开发者_JAVA技巧this code.
NSUserDefaults *userPrefs = [NSUserDefaults standardUserDefaults];
userPrefs setObject:filterimage forKey:@"FILTERIMAGE"];
with this code i try to get filterimage array data on another page.
FBImage = [[NSUserDefaults standardUserDefaults] valueForKey:@"FILTERIMAGE"];
FBImage is Array.
but get null in FBImage.
when i print data where i set user default it give like this.
-[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '(
"<null>",
"<null>",
"http://external.ak.fbcdn.net/safe_image.php?d=AQD44bnA250GMrV2&w=90&h=90&url=http%3A%2F%2Fwww.djmag.com%2Fimages%2Ftop100djs%2F2011header.jpg",
"http://external.ak.fbcdn.net/safe_image.php?d=AQD44bnA250GMrV2&w=90&h=90&url=http%3A%2F%2Fwww.djmag.com%2Fimages%2Ftop100djs%2F2011header.jpg",
"http://external.ak.fbcdn.net/safe_image.php?d=AQD44bnA250GMrV2&w=90&h=90&url=http%3A%2F%2Fwww.djmag.com%2Fimages%2Ftop100djs%2F2011header.jpg",
"<null>",
"<null>",
"<null>",
"<null>",
"<null>"
)' of class '__NSArrayM'
is this problem because of i will get null value in filter array?
I don't think it will solve all of your problems, but don't forget to synchronize your userDefaults after you change them:
[userPrefs synchronize];
if ([[NSUserDefaults standardUserDefaults] valueForKey:@"FILTERIMAGE"]==nil)
{
[[NSUserDefaults standardUserDefaults] setObject:filterimage forKey:@"FILTERIMAGE"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
then you can get where your want using entire application
FBImage = [[NSUserDefaults standardUserDefaults] valueForKey:@"FILTERIMAGE"];
NSUserDefaults can only contain a few data types: BOOL, double, float, NSInteger, NSNumber, NSData, NSString, NSDate, NSArray, NSDictionary, NSURL
. For other data types convert then to NSData or NSString.
Note that there are convince methods/functiions for many other data types to convert to and from NSStrings including NSStringFromCGAffineTransform, NSStringFromCGPoint, NSStringFromCGRect, NSStringFromCGSize, NSStringFromRange, NSStringFromUIEdgeInsets, NSStringFromUIOffset
and their counterparts to recreate the data types from the NSString
representations.
精彩评论