0

My tableView wasn't loading because tableView:cellForRowAtIndexPath: wasn't being called. The NSLog messages that I have written inside tableView:cellForRowAtIndexPath: did not appear in the console. I had a weak NSArray @property called listOfItems. When I changed it to strong, the tableView finally showed it's contents. Could someone please clarify if tableView:cellForRowAtIndexPath: wasn't being called because the NSArray was weak. Is there a connection between the listOfItems property and the tableView:cellForRowAtIndexPath: method being called?

Nicos Karalis
  • 3,724
  • 4
  • 33
  • 62
Martin Verdejo
  • 1,229
  • 2
  • 13
  • 24

1 Answers1

3

No object had a strong reference to the array. Your view controller had a reference, but it wasn't strong. This means that you don't care if it gets removed from memory, you don't need it to stick around. In this case, since your table relied on the data in the array, you don't want it to be removed from memory: you want it to stay around as long as the table stays around. To do so, you create a strong reference, which makes sure that that object isn't being removed from memory until that pointer (your property, in this case) didn't point to it anymore.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80