I’m a beginner in iOS development. I have a custom view:
@interface MyView : UIView {
In the ViewController, I add this view as a subview (would be better to do in another way, maybe in the Storyboard?):
MyView *myView = [[MyView alloc]initWithFrame:myFrame];
[self.view addSubview:myView];
in it, I follow the touches on screen, and I have a touchesEnded method:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// myValue is a class variable of MyView
myValue = doSomething();
}
Now, how can I get the value of myValue in the ViewController? Maybe a listener or a callback that can be invoked inside touchesEnded in MyView?
For instance, you can post a NSNotification in touchesEnded method of your view:
Listen for this notification in your view controller. To achieve that add in the view controller’s method viewDidLoad a line:
And then implement below method in your view controller: