Note that there are some explanatory texts on larger screens.

plurals
  1. POObj - C: Having trouble creating a UITableView that updates cells from an HTTP API in real-time (one at a time)
    text
    copied!<p>I am polling an HTTP API - it returns one item at a time, in real-time (about every 4 seconds). As each item is received, I would like a new UITableView cell to be populated. The full list of received items must remain in a class property, I'm guessing an NSMutableArray. What is the best way to initialize an NSMutableArray as a class property, update it as new information comes in, and then use the count to update a new UITableViewCell? Here's how I'm adding content to an NSMutableDictionary:</p> <pre><code>NSMutableDictionary *messageContents = [[NSMutableDictionary alloc] init]; [messageContents retain]; [messageContents setValue:messageText forKey:@"text"]; [messageContents setValue:image forKey:@"image"]; [self addMessageToDataArray:messageContents]; </code></pre> <p>Here's the method stuffing objects into the array:</p> <pre><code>- (void)addMessageToDataArray:(NSArray *)messageDictionary { [self.messageDataArray addObject:messageDictionary]; NSLog(@"count = %@", [self.messageDataArray count]); [self reloadTableData]; } </code></pre> <p>At this point, calling count on the messageDataArray class property crashes the application. I'm very used to working with arrays in Actionscript, Obj-C is obviously totally different. Please explain the method for instantiating an NSMutableArray as a class property, filling it with NSMutableDictionary's and then finding the NSMutableArray count (which will be dynamically updating in real-time) so I can use that info to update a UITableView (on the fly).</p> <p>Or... tell me I'm being silly and suggest a much easier solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload