Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a number of problems w/your code.</p> <ul> <li><p>you need to follow the standard initialization pattern of calling super's designated initializer and checking the return value.</p></li> <li><p>That method should be named <code>initWithId:word:card:</code> (i.e. case is wrong, hence the goofy coloring on StackOverflow, even).</p></li> <li><p>There is no need to implement a custom setter/getter if your setter/getter just follow the standard pattern. Use an @property and @synthesize.</p></li> <li><p>(from your screenshot) you really don't want to be directly triggering UI updates from your setter. Generally, anyway. Generally, you want your view layer to trigger an update of your model through the control and, once the model is fully updated, then let the view layer know it should reload.</p></li> <li><p>While you mention that you are instantiating an NSMutableArray instance, you don't show that in your code. Is <code>card.words</code> really set when you are adding <code>Word</code> instances?</p></li> </ul> <p>Show the -initWithId:card:type:used: (note I corrected the case) method's implementation.</p> <p>I.e. it better had have something like:</p> <pre><code> words = [NSMutableArray new]; // Or, if ARC, [NSMutableArray array]; </code></pre> <hr/> <p>OK -- next... </p> <ul> <li><p>put an <code>assert(card.words);</code> before your <code>while()</code> loop... that'll blow up if <code>words</code> isn't set.</p></li> <li><p>make sure that the <code>card</code> is non-nil (no reason why it shouldn't but... when the obvious stuff looks right, you check the <em>really</em> obvious stuff next)</p></li> </ul> <p>The comment about -reloadData is more that you would want to <code>reloadData</code> in whatever triggers the loading in the first place. Imagine a situation where you are loading several different kinds of data prior to updating the whole UI; maybe the table view has to be reloaded <em>and</em> some other stuff needs to be updated around it. By moving the <code>reloadData</code> out of the setter it (a) makes the setter simple and non-surprising while (b) makes it easier to refactor your UI layer such that multi-UI element updating can be done simultaneously.</p> <p>(Also -- please don't take my comments about coding style harshly... not meant to be... there are some subtle, but universal patterns to Obj-C coding. If you learn them and use them, it'll make your life a lot easier. We were all new to Obj-C once. Just that some of us were new to it while others of your weren't even born yet. ;).</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