I have a class that gets data from a repository and stuffs it into an NSArray:
EpisodeRepository Class
-(NSMutableArray *)getEpisodes {
NSMutableArray *episodes = [NSMutableArray array];
NSData *data = [self getDataFromAction:kGetEpisodesAction];
NSError *error = nil;
NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
for (NSDictionary *d in json) {
Episode *episode = [self buildEpisodeFromJSONDictionary:d];
[episodes addObject:episode];
}
return episodes;
}
In my view controller, I keep a reference to the repo and the array of episodes, like so:
@interface VideoController : UITableViewController
@property (nonatomic, strong) NSArray *episodes;
@property (nonatomic, strong) EpisodeRepository *episodeRepo;
In the implementation, what I want to happen is that every the view appears, refetch the data from the web services(in the EpisodeRepository) and reload the table view with the updated episodes. This works great the first time the tableview is populated. The problem is that when I call, cellForRowAtIndexPath, the episodes array is completely blank. It's not null, but there is no data whatsoever in it. The weird thing is that all the other tableView delegates realize that there is data in the array and act accordingly. What is special about cellForRowAtIndexPath and why would it possibly delete my entries in the array?
Here is the controller implementation:
-(id) initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if(self) {
episodeRepo = [[EpisodeRepository alloc] init];
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
[self loadContent];
[self.tableView reloadData];
[super viewWillAppear:animated];
}
-(void) loadContent {
self.episodes = [self.episodeRepo getEpisodes];
self.seasons = [self getSeasons:self.episodes];
[self setUILoaded];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//episodes is an empty array here???
}