How do you create a user control in UIKIt?

My subclass of UIView handles touch events and updates internal values ​​as it starts and as it tracks.

My view controller loads this custom view on the screen. What is the best way to configure the view controller to listen to changes in the value of my user control?

+3
source share
1 answer

You can:

  • Embed the delegate methods in your controller and call them from your view or
  • Subclass UIControland send UIControlEventto your controller

when the values ​​change (more precisely, when the user interacts with your control).

- , UIControl .

iPhone:

UIControl - : , , .

, UIView UIControl , . UIView , UIControl .

UPDATE:

, :

:

@interface MyView : UIView {
    id delegate;
}
@property (assign) id delegate;
@end

@synthesize .

:

MyView myView = [[MyView alloc] init];
[myView setDelegate:self];

, , (, touchesBegan), , , :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // Possibly change the values
    if([delegate respondsToSelector:@selector(valuesChanged)]) {
        [delegate valuesChanged];
    }
}

< Cocoa.

+8

Source: https://habr.com/ru/post/1705916/


All Articles