(This should be simple. But it has been driving me nuts for many hours.)
I am simply trying to call a ViewController method, from inside its UIView.
myViewController declares and creates a UIView:
myUIView = [[viewCreator alloc] init…];
and my myViewController also has a method:
-(void)inABottle{
NSLog(@"Hello.");
}
Inside the UIView, a UIButton is created. This button has a ‘selector’ to a method – in the UIView – which then tries to call the ‘inABottle’ method in the ViewController. Inside the UIView:
...
[myButton addTarget:self action:@selector(isPressed) forControlEvents:UIControlEventTouchUpInside];
-(void)isPressed{
[myViewController inABottle];// <<< This is where I have spent my day.
}
(The ViewController header file is #import ed in the UIView.)
Would really appreciate some help. Surely this should be simples!
Make a property in your view and set it to the current view controller when you create it:
viewcontroller.m:
view.h:
view.m:
Then just call the method like you are in your code in the question.
You should also look into how to use delegates, this is a perfect example of when you should use one.