In my code I store in the memory my array... To obtain it without make an HTML Request. the first time, when I populated my array everything is ok... the problems show up when I load array from the memory and load them in a table.
That's the class
@interface SubscriptionArray : NSObject{
NSString *title;
NSString *source;
NSString *htmlUrl;
NSInteger count;
}
@property (nonatomic,retain) NSString *title;
@property (nonatomic,retain) NSString *source;
@property (nonatomic,retain) NSString *htmlUrl;
@property (nonatomic) NSInteger count;
@end
#import "SubscriptionArray.h"
@implementation SubscriptionArray
@synthesize title,source,htmlUrl,count;
-(void)dealloc{
[title release];
[source release];
[htmlUrl release];
}
#pragma mark NSCoding
- (id)initWithCoder:(NSCoder *)decoder {
if (self = [super init]) {
title = [[decoder decodeObjectForKey:@"title"] retain];
source = [[decoder decodeObjectForKey:@"source"] retain];
htmlUrl = [[decoder decodeObjectForKey:@"htmlUrl"] retain];
count = [decoder decodeIntegerForKey:@"count"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
if (title) [encoder encodeObject:title forKey:@"title"];
if (source) [encoder encodeObject:source forKey:@"source"];
if (htmlUrl) [encoder encodeObject:htmlUrl forKey:@"htmlUrl"];
if (count) [encoder encodeInteger:count forKey:@"count"];
}
The array is declared in the delegate (to share with 3 different classes) as
NSMutableArray *onlySubsriptions; @property(nonatomic, retain)
NSMutableArray *onlySubsriptions;
And I load it in this way
[onlySubsriptions removeAllObjects];
self.onlySubsriptions = [NSKeyedUnarchiver unarchiveObjectWithFile:fullFileName];
And I received an error in the cellForRowAtIndexPath
for example I'm sure that I have 2 elements, the cellForRowAtIndexPath throws an exception when it start to load the 1st element (element 0)... it says deallocated instance.
I'm sure that the problem is on the encoding because the 1st time when I get the array everything is fine... Problems show up only when the next time I load my array that I store locally.
**** MORE INFO ABOUT ******
**** cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
TDBadgedCell *cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
SubscriptionArray * element=[[SubscriptionArray alloc]init];
if (indexPath.section==0) {
NSLog(@"CASO SPECIALELEMENTS");
element =[delegate.reader.specialElements objectAtIndex:[indexPath row]];
}
if (indexPath.section==1) {
NSLog(@"CASO CATEGORIA");
element =[delegate.reader.categories objectAtIndex:[indexPath row]];
}
if (indexPath.section==2) {
NSLog(@"CASO SUBSCRIPTIONS");
element =[delegate.reader.onlySubsriptions objectAtIndex:[indexPath row]];
}