Note that there are some explanatory texts on larger screens.

plurals
  1. POReusable NSView from .xib
    primarykey
    data
    text
    <p>In several parts of my application, I need a control where a user can enter a password. The password field is secure, however I want the user to have the ability to switch the field to plain text and check for typos, etc.</p> <p>The password field itself is no problem. I subclassed NSSecureTextField to get the behaviour I want. I make it bindable, so I can toggle the display from another control (say, a Checkbox).</p> <p><img src="https://i.stack.imgur.com/ABzOu.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/cNvkt.png" alt="enter image description here"></p> <p>Now, I want to reuse this in multiple places within my application. I can simply use my custom secure text field along side a checkbox everywhere I need this. But I would prefer to group these pieces together into a reusable component.</p> <p>So I create one using interface builder:</p> <p><img src="https://i.stack.imgur.com/o2T3W.png" alt="enter image description here"></p> <p>Now, how can I use that in my different windows? I have added a 'Custom View' component to my window, and set it's type appropriately:</p> <p><img src="https://i.stack.imgur.com/p1xxf.png" alt="enter image description here"></p> <p>But at runtime, I just get an empty space.</p> <p>1 - Presumably because my view is defined in a .xib - I need to do something in code to load my PasswordView instance from the .xib; but what exactly do I need to do? I'm having trouble working this out.</p> <p><strong>Specifically:</strong></p> <ul> <li><p><strong>What is the process / API to load an instance of my view from a .xib? I'm struggling to find the documentation on this.</strong></p></li> <li><p><strong>Once I have loaded an instance of my view, how to insert it in place of my Custom View 'placeholder'? Presumably I need an outlet to my custom view, but then what? Do I just assign my loaded instance to the outlet? Am I supposed to add it as a subview to the outlet?</strong></p></li> <li><p><strong>Where should this logic be happening? Inside init, inside AwakeFromNib?</strong></p></li> </ul> <p>2 - I know I can use an NSViewController for my custom view (<a href="https://stackoverflow.com/questions/3742720/loading-nsview-subclass-from-a-xib">example</a>), and load it that way. But do I really need a view controller just for this? It seems I should just be able to create standalone views and instantiate them easily... But perhaps this is not the Cocoa 'way'? It seems to me that there should be a straightforward way of composing a view from multiple .xibs without needing a controller for every sub view (which may just be a text field, or a button), but I'm just not finding it...</p> <p>Thank you in advance.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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