Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make sure you're either using a UITableViewController subclass as your VC (if you're using a UITableViewController ui object from the pallet), or that you're properly hooking up the UITableView's delegate and datasource properties to your VC (if you're using a plain UIViewController object and subclass). </p> <p>(see comments on question). </p> <p>Try this:</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog(@"bookLibrary.count %d", bookLibrary.count); return [bookLibrary count]; } </code></pre> <p>You'll find that things are not what you think they are... Add in an implementation of <code>viewDidLoad</code> and <code>viewWillAppear</code> along with that, each with their own "I'm here" NSLog statement, and trace the flow of that second view controller appearing. Again, you'll find you've got some sequencing issues where the flow isn't working quite the way you might be assuming. </p> <hr> <p>Added comment:</p> <p>Ultimately, the origin of your problem is this line in your "sending" controller's prepare for segue method:</p> <pre><code>controller.bookLibrary = [self.entries allValues]; </code></pre> <p>What is this doing? It's calling <code>allValues</code> on the Dictionary object. That method generates a new array (!) containing the values. You don't store that new Array object in any permanent storage. You just use it to set: </p> <pre><code>controller.bookLibrary = ... </code></pre> <p>So, right after that statement executes, you have:</p> <ul> <li>an Array object in your prepareForSegue method (where the code is executing) that you've only stored in one variable/holder, which is:</li> <li>a <em>weak</em> pointer to that object over in your destination view controller (TableViewController)</li> </ul> <p>The method ends. </p> <p>The Array returned by <code>[... allValues]</code> is not being held on to by anything in the Source view controller, so the only thing holding it from being garbage collected is the pointer to it in the Destination view controller. </p> <p>But that pointer is a <em>weak</em> pointer. By definition, if that's the only pointer to an object, the pointer will be set to nil and the object released for garbage collection. <em>Poof!</em> No more array object, and you're left holding a nil pointer. </p> <p>As you discovered, setting the "receiver" to <em>strong</em> lets it hold on to that Array object, even after the other code exits and it's the only pointer to the Array.</p> <p>(And, your code isn't being invoked twice. If you look closely at the logging -- or better yet set a breakpoint inside the table get-row-count method -- you'll see it's only being called once. The earlier logging of "I have 8 objects" is happening over in other code, not in your TableViewController.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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