Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As @Inazfiger says, your objects need at least one strong (retaining) reference, otherwise they won't be retained.</p> <p>In this case, you're assigning the picker view to a <code>UITextField</code>'s <code>inputView</code> property. The text field will retain the picker view (I know this because the <code>inputView</code> property on <code>UITextField</code> is <a href="https://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instp/UITextField/inputView" rel="noreferrer">declared with the modifiers "readwrite, <strong>retain</strong>"</a>), but <strong>only once you've made the assignment</strong>. So if you want to stick with a weak reference, you need to rearrange your code slightly - something like this:</p> <pre><code>// Declare a temporary UIPickerView reference. By default, this is // a strong reference - so tempPicker will be retained until this // variable goes out of scope. UIPickerView *tempPicker = [[UIPickerView alloc] initWithFrame:frame]; // Configure the picker tempPicker.delegate = self; tempPicker.dataSource = self; // Assign the picker view to the text field's inputView property. This // will increase the picker's retain count. Now it'll no longer be // released when tempPicker goes out of scope. textField.inputView = tempPicker; // Finally, assign the same object to self.levelPicker - it won't // go out of scope as long as it remains assigned to textField's // inputView property, and textField itself remains retained. self.levelPicker = tempPicker; </code></pre>
 

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