I am trying to create a basic app that displays event information from a server.
So far I download all the information in an xml file and parse it using NSXMLParser.
I have an event object that I have created that stores all of the information for each event, I then populate a NSMutableArray with these events.
I would like to then asynchronously load the images relating to each event as each UITableView Cell displays, and store them in a NSData in the event objects located within the NSMutableArray. This way I would only load images that I need.
The layout of my NSMutableArray looks like this(simplified):
events
-event1
-(NSString *)title
-(NSURL *)imageURL
-(NSData *)eventData
-event2
-(NSString *)title
-(NSURL *)imageURL
-(NSData *)eventData
etc..
I have no idea what the best practice here is and am struggling to make it work.
Option 1
I can try to set it straight from the MasterViewController, this doesn't seem right to me, and I get an error. If I use the code[[events objectAtIndex:cellIndexPath.row] eventImageData] = [[NSData alloc] initWithContentsOfURL:[[events objectAtIndex:cellIndexPath.row] eventImgURL]];
I get the error: expression not assignable
- Option 2
I can write a method within the event object itself to download the image. I did this, and for the life of me couldn't get the event object to ask the MasterViewController to refresh the appropriate NSTableViewCell once it had finished getting the image.
My question is, am I on the right track with either of these trains of thought? Can I allocate a new NSData inside of an object within a NSMutableArray? or was I on the right track asking the event object to download it's own image?
Thanks for taking the time to read this overly-long-winded question.