Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can:</p> <ol> <li>Implement delegate methods in your controller and call them from your view, or</li> <li>Subclass <code>UIControl</code> instead and send <code>UIControlEvent</code>s to your controller</li> </ol> <p>when the values change (or rather when the user interacts with your control).</p> <p>If your view is used to get some form of input from the user, then subclassing <code>UIControl</code> is a better approach.</p> <p>From the iPhone Reference Library:</p> <blockquote> <p><code>UIControl</code> is the base class for controls: objects such as buttons and sliders that are used to convey user intent to the application.</p> </blockquote> <p>So the most important distinction between <code>UIView</code> and <code>UIControl</code> is whether user intent is conveyed or not. <code>UIView</code> is meant to display information, while <code>UIControl</code> is meant to collect user input.</p> <p><strong>UPDATE:</strong></p> <p>If you decide to go with the delegate pattern, here's how your code might look like:</p> <p>In your custom view's interface, define delegate like this:</p> <pre><code>@interface MyView : UIView { id delegate; } @property (assign) id delegate; @end </code></pre> <p>and <code>@synthesize</code> it in the implementation.</p> <p>In your view controller, set the controller to be the delegate:</p> <pre><code>MyView myView = [[MyView alloc] init]; [myView setDelegate:self]; </code></pre> <p>Then, whenever the user interacts with the view (for example in <code>touchesBegan</code>), possibly changing the values, do this in the view:</p> <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { // Possibly change the values if([delegate respondsToSelector:@selector(valuesChanged)]) { [delegate valuesChanged]; } } </code></pre> <p>You might also want to take a look at <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html#//apple_ref/doc/uid/TP40002974-CH7-SW18" rel="nofollow noreferrer">Delegates and Data Sources</a> in the Cocoa Fundamentals Guide.</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