Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You'll only end up with five items if <code>tableView:numberOfRowsinSection:</code> returns <code>5</code>. Thats the simple answer to your question, but I see other problems here. I'm wondering why you have this test: <code>row &lt; recentItems.count</code>. Is that array the same thing as <code>[ItemsController sharedItemsController].count</code>? You really need to be using the same array for both methods.</p> <p>(Also, it's not a syntax error, but you shouldn't use the property syntax for things that aren't declared as properties. You should write <code>[recentItems count]</code> instead.)</p> <p>I'm also confused by the code you use to set up the cell. Cells are meant to be reusable. That is, you create one cell, then reconfigure it every time in your implementation of <code>tableView:cellForRowAtIndexPath:</code>. Your code creates a cell for each item in your list. This is very memory-inefficient, and will likely crash your program due to insufficient memory on the iPhone if you keep lots of cells in memory like this.</p> <p>The recommended approach is to call <code>dequeueReusableCellWithIdentifier:</code>. If that returns <code>nil</code>, then you set up a cell using the <code>initWithFrame:reuseIdentifier:</code> initializer. The table view is very smart, and will only ask you to redraw the cell when it needs you to.</p> <p>Your <code>recentCellData</code> dictionary looks really shaky to me, too. What if you insert an item after the item with key <code>@"2"</code>? All the items with key <code>@"3"</code> onward will need to be shifted one element to the right to work the way you expect. That's a ton of bookkeeping that seems rather unnecessary to me. If you really needed something like this -- and to be clear, I don't think you do -- why wouldn't you use an <code>NSMutableArray</code>, which is much easier to use?</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