Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since this has been the accepted answer for a long time, I feel I need to rectify it with a better answer.</p> <p>Some comments on the need:</p> <ul> <li>Your view should not need to access the view controller directly.</li> <li>The view should instead be independent of the view controller, and be able to work in different contexts.</li> <li>Should you need the view to interface in a way with the view controller, the recommended way, and what Apple does across Cocoa is to use the delegate pattern.</li> </ul> <p>An example of how to implement it follows:</p> <pre><code>@protocol MyViewDelegate &lt; NSObject &gt; - (void)viewActionHappened; @end @interface MyView : UIView @property (nonatomic, assign) MyViewDelegate delegate; @end @interface MyViewController &lt; MyViewDelegate &gt; @end </code></pre> <p>The view interfaces with its delegate (as <code>UITableView</code> does, for instance) and it doesn't care if its implemented in the view controller or in any other class that you end up using.</p> <p>My original answer follows: <em>I don't recommend this, neither the rest of the answers where direct access to the view controller is achieved</em></p> <p>There is no built-in way to do it. While you can get around it by adding a <code>IBOutlet</code> on the <code>UIView</code> and connecting these in Interface Builder, this is not recommended. The view should not know about the view controller. Instead, you should do as @Phil M suggests and create a protocol to be used as the delegate.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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