我想archieve NS與圖像mustable陣列,我的代碼如下所示:Archieve NSMutable數組包含的UIImage
//in my .h file I have
#define kName @"name"
#define kEmail @"email"
#define kPhone @"phone"
#define kDetail @"detail"
#define kImages @"images"
#define kRequestDate @"requestDate"
#define kRequestSent @"status"
@interface BAPRequest : NSObject
@property (nonatomic) NSString *name;
@property (nonatomic) NSString *email;
@property (nonatomic) NSString *phone;
@property (nonatomic) NSString *detail;
@property (nonatomic) NSMutableArray *images;
@property (nonatomic) NSDate *requestDate;
@property (nonatomic) BOOL requestSent;
@end
//in my .m file I have
#import "BAPRequest.h"
@implementation BAPRequest
@synthesize name, email, phone, detail;
@synthesize images;
@synthesize requestDate;
@synthesize requestSent;
- (void)encodeWithCoder:(NSCoder *)encoder{
[encoder encodeObject:name forKey:kName];
[encoder encodeObject:email forKey:kEmail];
[encoder encodeObject:phone forKey:kPhone];
[encoder encodeObject:detail forKey:kDetail];
[encoder encodeObject:images forKey:kImages];
[encoder encodeObject:requestDate forKey:kRequestDate];
[encoder encodeBool:requestSent forKey:kRequestSent];
}
- (id)initWithCoder:(NSCoder *)decoder{
name = [decoder decodeObjectForKey:kName];
email = [decoder decodeObjectForKey:kEmail];
phone = [decoder decodeObjectForKey:kPhone];
detail = [decoder decodeObjectForKey:kDetail];
images = [decoder decodeObjectForKey:kImages];
requestDate = [decoder decodeObjectForKey:kRequestDate];
requestSent = [decoder decodeBoolForKey:kRequestSent];
return self;
}
@end
當然
我也有代碼的NSKeyedArchiver也像其他人一樣。
其他一切都會正確存檔,當我保存然後加載它們時,它似乎全部正常工作。
但歸檔圖像似乎沒有。
我確實有一個MutableArray歸檔每個BAPObjects以及歸檔之前,奇怪是因爲ios不支持在MutableArray內部歸檔MutableArray還是僅僅因爲我無法輕鬆歸檔圖像?
乾杯 菲爾
是否必須使用編碼或解碼編寫我自己的UIIMage類,或者是否可以覆蓋其編碼/解碼(如果有)?如果你能舉個小例子,這將是非常棒的。 – phil88530
請檢查我的編輯 –
我已經添加了UIImage + NSCoding來幫助編碼圖像(來自rob的建議),但它仍然無效。假設我添加了編碼類別,它會被編譯,我必須在某處包含UIImage + NSCoding.h嗎? – phil88530